Re: [閒聊] 每日leetcode

看板Marginalman作者 (dont)時間1年前 (2024/09/14 14:24), 編輯推噓1(100)
留言1則, 1人參與, 1年前最新討論串858/1554 (看更多)
2419. Longest Subarray With Maximum Bitwise AND ## 思路 AND值會變小, 所以目標是找裡面都是相同最大值的subarray 用while迴圈感覺好長 唉 ## Code ```python class Solution: def longestSubarray(self, nums: List[int]) -> int: res = curr_max = 0 i, n = 0, len(nums) while i < n: cnt = 1 while i + cnt < n and nums[i+cnt] == nums[i]: cnt += 1 if nums[i] > curr_max: curr_max, res = nums[i], cnt elif nums[i] == curr_max: res = max(res, cnt) i += cnt return res ``` -- https://i.imgur.com/kyBhy6o.jpeg
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 185.213.82.187 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1726295093.A.A35.html

09/14 14:38, 1年前 , 1F
大師
09/14 14:38, 1F
文章代碼(AID): #1cvImrer (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1cvImrer (Marginalman)