Re: [閒聊] 每日leetcode

作者: DJYOMIYAHINA (通通打死)   2024-09-14 10:33:03
反正and不可能越and越大
所以就找所有element都=最大值的最長sub array
def longestSubarray(self, nums: List[int]) -> int:
maximum = max(nums)
max_sub_len, cur = 0, 0
for n in nums:
if n==maximum:
cur += 1
max_sub_len = max(max_sub_len, cur)
else:
cur = 0
return max_sub_len

Links booklink

Contact Us: admin [ a t ] ucptt.com