We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7529ce6 commit 60a4870Copy full SHA for 60a4870
2401-longest-nice-subarray.js
@@ -0,0 +1,30 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @return {number}
4
+ */
5
+var longestNiceSubarray = function(nums) {
6
+ let max = 1;
7
+ let stack = [];
8
+ for(let i =0;i<nums.length;i++){
9
+ if(nums[i]&nums[i+1]) continue;
10
+ stack.push(nums[i])
11
+ for(let j =i+1;j<nums.length;j++){
12
+ let state = true;
13
+ for(el of stack){
14
+ if(el&nums[j]){
15
+ state=false;
16
+ break;
17
+ }
18
19
+ if(state) {
20
+ stack.push(nums[j]);
21
+ max = Math.max(max,stack.length);
22
23
+ else{
24
+ stack = []
25
26
27
28
29
+ return max;
30
+};
0 commit comments