[Python] str 先比較 len 再比較 Lexicographic Order
min(..., key=lambda s: (len(s), s)) Ref: Lexicographic Order
min(..., key=lambda s: (len(s), s)) Ref: Lexicographic Order
https://leetcode.com/problems/missing-element-in-sorted-array Solution Time Complexity: O(len(nums)) Space Complexity: O(1) (The input and output generally do not count towards the space complexity.) ...
https://leetcode.com/problems/soup-servings Solution: DP, Bottom-Up 湯a 數量為 na ,湯b 數量為 nb ma := ceil(na / 25) mb := ceil(nb / 25) dp[ma][mb] 則為回傳的答案 dp[0][0] = 0.5 ma == 0, mb > 0 ⇒ dp = 1 ma > 0 ...
global global_stmt ::= "global" identifier ("," identifier)* 在 global 中宣告的此層級中的 identifier(s) 將會對應為 global 變數 例: counter = 0 def func_a(): global counter counter += 2 print('func_a counter ...
字母/國際音標 對照 Alphabet IPA a a stock [stak] ɑ hot [hɑt] an ɑ̃ b b c s d e e may [meː] ɛ bed [bɛd] ə eu ø en ɑ̃ f g h i i j j k l l m n n o o yawn ...
str vs list c in [“c0“, “c1“, “c2“, …] c in “c0c1c2…”
https://leetcode.com/problems/predict-the-winner Solution (Recursive) Time Complexity: O(2 ** len(nums)) Space Complexity: O(len(nums)) (The input and output generally do not count towards the space c ...
str.ljust(width[, fillchar]) str.rjust(width[, fillchar])
f-string f"...{variable}..." 輸出位數 {v:N} Space Padding {v:N} 0 Padding {v:0N} Decimal Places {v:B.Af} / {v:.Af} Justified string {v:>N} 註:N, A, B 等不可是變數,當位數非常數時請參考 rjust() 其他舊的 String Format ...
Modulo 除數(Division)的選擇:質數 為什麼除數藥選擇質數呢? 我們選擇 modulo 作為 hash function 是想藉此將 整數 Z 映射到 [0, 1, 2, …, N – 1] (N 為除數) 假設 被除數 M 和 除數 N 有最大公因數 k $$ M = km, N = kn; m, n, k \in \mathbb{N} $$ \begin{ ...