Skip to content

Commit 6a42cca

Browse files
authored
Create longest-subarray-with-maximum-bitwise-and.py
1 parent 6d136a2 commit 6a42cca

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
# bit manipulation
5+
class Solution(object):
6+
def longestSubarray(self, nums):
7+
"""
8+
:type nums: List[int]
9+
:rtype: int
10+
"""
11+
mx = max(nums)
12+
result, l = 1, 0
13+
for x in nums:
14+
if x == mx:
15+
l += 1
16+
result = max(result, l)
17+
else:
18+
l = 0
19+
return result

0 commit comments

Comments
 (0)