Hash-Table
LeetCode 997: Find the Town Judge
·1 分鐘
LeetCode
Easy
Array
Hash-Table
Graph
LeetCode 997 解題筆記:法官被其他 n - 1 個人信任而且不信任任何人,所以 in-degree - out-degree == n - 1
LeetCode 1002: Find Common Characters
·1 分鐘
LeetCode
Easy
Array
Hash-Table
String
LeetCode 1002 解題筆記:每個單字各自計數,對所有 Counter 取交集(每個字元取最小次數),再展開
LeetCode 961: N-Repeated Element in Size 2N Array
·1 分鐘
LeetCode
Easy
Array
Hash-Table
Pigeonhole-Principle
LeetCode 961 解題筆記:其他 n 個數都不同,所以第一個出現第二次的數就是答案
LeetCode 953: Verifying an Alien Dictionary
·1 分鐘
LeetCode
Easy
Array
Hash-Table
String
LeetCode 953 解題筆記:把字母對應到外星順序的 index,相鄰兩個單字找第一個不同的字元比較,沒有不同時短的要在前面
LeetCode 929: Unique Email Addresses
·1 分鐘
LeetCode
Easy
Array
Hash-Table
String
LeetCode 929 解題筆記:用 @ 切開,只處理 local 的部分(+ 之後丟掉、去掉 .),接回 domain 後放進集合
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 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 859: Buddy Strings
·1 分鐘
LeetCode
Easy
Hash-Table
String
LeetCode 859 解題筆記:長度要相同;完全相同時要有重複字元;否則剛好兩個位置不同而且交叉相等
LeetCode 819: Most Common Word
·1 分鐘
LeetCode
Easy
Array
Hash-Table
String
Counting
LeetCode 819 解題筆記:標點換成空白、全部轉小寫再切單字,計數後找出不在 banned 裡的最多的那個
LeetCode 804: Unique Morse Code Words
·1 分鐘
LeetCode
Easy
Array
Hash-Table
String
LeetCode 804 解題筆記:把每個單字轉成摩斯碼字串,放進集合後算有幾種
LeetCode 771: Jewels and Stones
·1 分鐘
LeetCode
Easy
Hash-Table
String
LeetCode 771 解題筆記:把 jewels 放進集合,數 stones 裡有幾個字元在集合裡