We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f7bb89c commit 184887fCopy full SHA for 184887f
2401-longest-nice-subarray/2401-longest-nice-subarray.cpp
@@ -0,0 +1,35 @@
1
+class Solution {
2
+public:
3
+ int longestNiceSubarray(vector<int>& nums) {
4
+ vector<int> on(33);
5
+
6
+ auto op = [&](int x, int y) {
7
+ for (int i = 0; i < 31; i++) {
8
+ if ((1 << i) & x) {
9
+ on[i] += y;
10
+ }
11
12
+ };
13
14
+ auto ok = [&](int x) {
15
16
17
+ if (on[i]) return false;
18
19
20
+ return true;
21
22
23
+ int n = nums.size();
24
+ int ans = 0;
25
+ for (int l = 0, r = 0; r < n; r++) {
26
+ while (!ok(nums[r])) {
27
+ op(nums[l], -1);
28
+ l++;
29
30
+ op(nums[r], 1);
31
+ ans = max(ans, r - l + 1);
32
33
+ return ans;
34
35
+};
0 commit comments