Skip to content

Commit 9074cb3

Browse files
authored
Create
1 parent 5d90cd7 commit 9074cb3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Time: O(n)
2+
// Space: O(n)
3+
4+
// freq table, combinatorics
5+
class Solution {
6+
public:
7+
long long beautifulSubarrays(vector<int>& nums) {
8+
unordered_map<int64_t, int> cnt = {{0, 1}};
9+
int64_t result = 0, curr = 0;
10+
for (const auto& x : nums) {
11+
curr ^= x;
12+
result += cnt[curr]++;
13+
}
14+
return result;
15+
}
16+
};

0 commit comments

Comments
 (0)