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...