20 lines
592 B
Python
20 lines
592 B
Python
# 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
|