↓快轉到主要內容

LeetCode

LeetCode 925: Long Pressed Name
·1 分鐘
LeetCode Easy Two-Pointers String
LeetCode 925 解題筆記:兩個指標分別走 name 和 typed,typed 的字元要嘛對到 name 的下一個字,要嘛是前一個字的長按
LeetCode 922: Sort Array By Parity II
·1 分鐘
LeetCode Easy Array Two-Pointers Sorting
LeetCode 922 解題筆記:偶數位置的指標 i、奇數位置的指標 j,各自跳兩格;i 放錯(奇數)時讓 j 找到放錯的偶數再交換
LeetCode 917: Reverse Only Letters
·1 分鐘
LeetCode Easy Two-Pointers String
LeetCode 917 解題筆記:左右指針各自跳過非字母,兩邊都是字母時交換;字串要先轉成 list 才能改
LeetCode 914: X of a Kind in a Deck of Cards
·1 分鐘
LeetCode Easy Array Hash-Table Math Counting
LeetCode 914 解題筆記:每種卡片的張數都要能被同一個 X >= 2 整除,也就是所有張數的 GCD >= 2
LeetCode 908: Smallest Range I
·1 分鐘
LeetCode Easy Array Math
LeetCode 908 解題筆記:最大值往下調 k、最小值往上調 k,答案是 max(0, max - min - 2k)
LeetCode 905: Sort Array By Parity
·1 分鐘
LeetCode Easy Array Two-Pointers Sorting
LeetCode 905 解題筆記:寫入指標把偶數交換到前面,跟 move zeroes 一樣
LeetCode 897: Increasing Order Search Tree
·1 分鐘
LeetCode Easy Stack Tree Depth-First-Search Binary-Search-Tree
LeetCode 897 解題筆記:中序遍歷,依序把節點接到一條只有右小孩的鏈上,左小孩設成 None;dummy 和移動的尾巴要分開
LeetCode 896: Monotonic Array
·1 分鐘
LeetCode Easy Array
LeetCode 896 解題筆記:單調可以是非遞增或非遞減,兩個方向各檢查一次,相等的元素都可以
LeetCode 892: Surface Area of 3D Shapes
·1 分鐘
LeetCode Easy Array Math Geometry Matrix
LeetCode 892 解題筆記:每疊 v 個方塊有 4v + 2 個面,再扣掉跟上方和左方相鄰的疊重疊的 2 × min 面
LeetCode 888: Fair Candy Swap
·1 分鐘
LeetCode Easy Array Hash-Table Binary-Search Sorting
LeetCode 888 解題筆記:交換 x 和 y 後總和相等,代表 y = x + (sumB - sumA) / 2;把 B 放進集合,逐一檢查 A 的 x
LeetCode 884: Uncommon Words from Two Sentences
·1 分鐘
LeetCode Easy Hash-Table String Counting
LeetCode 884 解題筆記:把兩個句子合起來數每個單字的次數,只出現一次的就是答案
LeetCode 883: Projection Area of 3D Shapes
·1 分鐘
LeetCode Easy Array Math Geometry Matrix
LeetCode 883 解題筆記:俯視是非 0 的格子數,正視和側視分別是每一列、每一欄的最大值總和