Skip to content

Commit 3d7932c

Browse files
authored
Update 2401-longest-nice-subarray.js
1 parent d2d5a9d commit 3d7932c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

2401-longest-nice-subarray.js

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
const longestNiceSubarray = function (nums) {
6+
const n = nums.length
7+
let i = 0, mask = 0, res = 0
8+
for(let j = 0; j < n; j++) {
9+
const e = nums[j]
10+
while((mask & e) !== 0) {
11+
mask ^= nums[i]
12+
i++
13+
}
14+
mask |= e
15+
res = Math.max(res, j - i + 1)
16+
}
17+
return res
18+
}
19+
20+
// another
21+
122
/**
223
* @param {number[]} nums
324
* @return {number}

0 commit comments

Comments
 (0)