Tag: leetcode
All the articles with the tag "leetcode".
-
leetcode 1022. Sum of Root To Leaf Binary Numbers [Easy]
DFS 遍歷所有根到葉的路徑,以位元左移方式累積二進位值並求和,解析 Sum of Root To Leaf Binary Numbers。
-
leetcode 997. Find the Town Judge [Easy]
以入度(被信任次數)與出度(信任他人次數)的條件找出唯一滿足鎮長條件的人,解析 Find the Town Judge。
-
leetcode 1010. Pairs of Songs With Total Durations Divisible by 60 [Medium]
用大小為 60 的 array 記錄每個 time%60 的出現次數,以 O(n) 找出所有兩兩相加為 60 倍數的配對,解析 Pairs of Songs Divisible by 60。
-
leetcode 1026. Maximum Difference Between Node and Ancestor [Medium]
DFS 過程中同時傳遞路徑上的最大值與最小值,在每個節點計算最大差值,解析 Maximum Difference Between Node and Ancestor。
-
leetcode 116. Populating Next Right Pointers in Each Node [Medium]
利用 BFS 逐層連結完全二元樹每個節點的 next 指標,解析 Populating Next Right Pointers in Each Node 的思路。
-
leetcode 876. Middle of the Linked List [Medium]
使用快慢指標,快指標每次走兩步、慢指標走一步,快指標到終點時慢指標即在中點,解析 Middle of the Linked List。
-
leetcode 476. Number Complement [Medium]
找出有效位元的最大 mask,再與原數做 XOR 取得補數,解析 Number Complement 的位元操作思路。
-
leetcode 198. House Robber [Medium]
DP 經典題:以 dp[i] = max(dp[i-1], dp[i-2]+nums[i]) 在不相鄰的限制下求陣列最大總和,解析 House Robber 的狀態轉移。