This commit is contained in:
parent
ca8fea83c0
commit
4ee9bc38cb
1 changed files with 20 additions and 0 deletions
20
medium/longest_subarray_with_maximum_bitwise_and.py
Normal file
20
medium/longest_subarray_with_maximum_bitwise_and.py
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
# https://leetcode.com/problems/longest-subarray-with-maximum-bitwise-and
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
class Solution:
|
||||||
|
def longestSubarray(self, nums: List[int]) -> int:
|
||||||
|
max_value = 0
|
||||||
|
max_length = 0
|
||||||
|
current_length = 0
|
||||||
|
|
||||||
|
for num in nums:
|
||||||
|
if num > max_value:
|
||||||
|
max_value = num
|
||||||
|
max_length = current_length = 1
|
||||||
|
elif num == max_value:
|
||||||
|
current_length += 1
|
||||||
|
max_length = max(max_length, current_length)
|
||||||
|
else:
|
||||||
|
current_length = 0
|
||||||
|
|
||||||
|
return max_length
|
||||||
Loading…
Add table
Add a link
Reference in a new issue