Skip to content

Commit 56efd79

Browse files
authored
Create 2401. Longest Nice Subarray
1 parent 03bf314 commit 56efd79

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

2401. Longest Nice Subarray

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
int longestNiceSubarray(vector<int>& nums) {
4+
int n=nums.size();
5+
int left=0, right=0, maxi=INT_MIN;
6+
while(right<n){
7+
bool isNice=true;
8+
for(int i=left; i<right; i++){
9+
if((nums[i] & nums[right])!=0){
10+
isNice=false;
11+
break;
12+
}
13+
}
14+
if(isNice){
15+
maxi=max(maxi, (right-left)+1);
16+
right++;
17+
}
18+
else{
19+
left++;
20+
}
21+
}
22+
return maxi;
23+
}
24+
};

0 commit comments

Comments
 (0)