110 Balanced Binary Tree thoughts 平衡樹定義:每個節點的左右子樹高度差 ≤ 1 遞迴計算高度:若某個子樹不平衡,回傳 -1...
543 Diameter of Binary Tree thoughts 樹的直徑:任意兩個節點之間的最長路徑(經過 root 或不經 root)。 DFS...
Maximum Subarray (LeetCode 53, Kadane’s Algorithm) 解題思路 動態規劃: dp[i] = 以 nums[...
Move Zeroes (LeetCode 283, Two Pointers) 解題思路 使用 快慢指針: slow:下一個非零要放的位置 fast:遍歷...
Find Peak Element (LeetCode 162, Binary Search) thoughts 峰值定義:nums[i] > nums...
Rotate Array (LeetCode 189) thoughts 將陣列右旋轉 k 步。 常見解法: 使用額外陣列 (O(n) 空間) 反轉法 (O...
Linked List Cycle (LeetCode 141) thoughts 使用 Floyd’s Cycle Detection (快慢指針): sl...
Reorder List (LeetCode 143) thoughts 將鏈表重新排序:L0 → Ln → L1 → Ln-1 → … 步驟: 找到中點...
Middle of the Linked List (Linked List) 876 question 給定一個單向鏈結串列,找到其中間節點並回傳。 如果有...