Re: [閒聊] 每日leetcode

看板Marginalman作者 (可可粉)時間1年前 (2024/09/14 15:22), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串859/1554 (看更多)
※ 引述《dont (dont)》之銘言: : 2419. Longest Subarray With Maximum Bitwise AND 看了hint才知道AND的習性 複習個sliding window O(n) C#: public int LongestSubarray(int[] nums) { int maxLength = 0, max = 0, left = 0, right = 0; while (right < nums.Length) { if (max < nums[right]) { max = nums[right]; maxLength = 1; left = right; } else if (max == nums[right]) { maxLength = Math.Max(maxLength, right - left + 1); } else { left = right + 1; } right++; } return maxLength; } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.168.225.75 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1726298520.A.08F.html
文章代碼(AID): #1cvJcO2F (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1cvJcO2F (Marginalman)