Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static long getChannelRating(List<Integer> views) {
- long ans = 0;
- long modd = 1000000007;
- Map<Long, Long> m = new HashMap<>();
- m.put(0L, 1L);
- long p = 0;
- List<Long> pre = new ArrayList<>(views.size());
- for (int i = 0; i < views.size(); i++) {
- p ^= views.get(i);
- if (i >= 2) {
- ans += m.getOrDefault(p, 0L);
- ans %= modd;
- if (views.get(i) == 0) {
- ans--;
- }
- if (views.get(i).equals(views.get(i - 1))) {
- ans--;
- }
- if (ans < 0) {
- ans += modd;
- }
- }
- m.put(p, m.getOrDefault(p, 0L) + 1);
- pre.add(p);
- }
- return (int)ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement