討論串[閒聊] 每日leetcode
共 1554 篇文章

推噓4(4推 0噓 2→)留言6則,0人參與, 1年前最新作者DJYOMIYAHINA (通通打死)時間1年前 (2024/11/07 21:45), 編輯資訊
0
0
0
內容預覽:
每個bit去算 candidates裡面有幾個數字的這個bit是1. 最多的那個就是答案. def largestCombination(self, candidates: List[int]) -> int:. cnt = defaultdict(int). ans = 0. for sft in
(還有102個字)

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者dont (dont)時間1年前 (2024/11/07 19:19), 編輯資訊
0
0
0
內容預覽:
2275. Largest Combination With Bitwise AND Greater Than Zero. ## 思路. 記錄每個bit的數量, 回傳最大值. 用count array記錄 space是O(N). 把for loop順序對調就O(1)了. eg. [1,3,4,5].
(還有635個字)

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者devilkool (可可粉)時間1年前 (2024/11/07 01:59), 編輯資訊
0
0
0
內容預覽:
3011. Find if Array Can Be Sorted. 偷看hint才會寫,假如相鄰兩數字二進位的1的數量不一樣. 前面又比後面大的話就是false,1的數量一樣的話就找出這一組最大的值跟下一組做比較. public bool CanSortArray(int[] nums). {.
(還有794個字)

推噓6(6推 0噓 0→)留言6則,0人參與, 1年前最新作者DJYOMIYAHINA (通通打死)時間1年前 (2024/11/06 22:58), 編輯資訊
0
0
0
內容預覽:
直接硬幹 很慢 但可以. def canSortArray(self, nums: List[int]) -> bool:. n = len(nums). for i in range(n):. for j in range(n-i-1):. if nums[j]>nums[j+1]:. cnt_l
(還有1018個字)

推噓0(0推 0噓 0→)留言0則,0人參與, 最新作者JIWP (神楽めあ的錢包)時間1年前 (2024/11/06 21:20), 編輯資訊
0
0
0
內容預覽:
3011. Find if Array Can Be Sorted. 有一個0-indexed的正整數矩陣 : nums. 在每個操作你可以把滿足以下條件相鄰的兩個元素位置交換. 這兩個元素用2進位表示時,1(set bits)的數量是相等的. 可以進行任意次操作. 請問有辦法把nums變成有序(遞
(還有1176個字)