Skip to content

Commit 4ae12b2

Browse files
authored
Create 2419. Longest Subarray With Maximum Bitwise AND (#585)
2 parents 7fac59c + 8efc798 commit 4ae12b2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int longestSubarray(vector<int>& nums) {
4+
int ans = 0, count = 0;
5+
int maxi = *max_element(nums.begin(), nums.end());
6+
7+
for(int i = 0; i<nums.size(); i++){
8+
if(nums[i] == maxi){
9+
count++;
10+
ans = max(ans, count);
11+
}
12+
else{
13+
count = 0;
14+
}
15+
}
16+
return ans;
17+
}
18+
};

0 commit comments

Comments
 (0)