Skip to content

Commit 8139ac0

Browse files
authored
Update 2401-longest-nice-subarray.js
1 parent 19c71dc commit 8139ac0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

2401-longest-nice-subarray.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
const longestNiceSubarray = function (nums) {
6+
let res = 1, i = 0, j = 0, mask = 0
7+
const n = nums.length
8+
for(i = 0; i < n; i++) {
9+
const cur = nums[i]
10+
while((cur & mask) !== 0) {
11+
mask ^= nums[j]
12+
j++
13+
}
14+
mask |= cur
15+
// console.log(i, j, mask, i - j +1)
16+
res = Math.max(res, i - j + 1)
17+
}
18+
19+
return res
20+
}
21+
22+
// another
23+
124
/**
225
* @param {number[]} nums
326
* @return {number}

0 commit comments

Comments
 (0)