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{ ...
https://leetcode.com/problems/design-hashmap Solution 以 modulo 作為 hash function 作為 modulo 的除數 我選擇了六位數中最小的質數 100003 同時這也會變成 hash table 的容量 Time Complexity: O() Space Complexity: O() (The input and outp ...
https://leetcode.com/problems/add-two-numbers-ii Solution Time Complexity: O(max(len(l1), len(l2))) Space Complexity: O(1) (The input and output generally do not count towards the space complexity.) c ...
https://leetcode.com/problems/add-two-numbers Solution 可能由 Multiple Assignment 引發的錯誤 cur.next, cur = ListNode(1), cur.next 計算 ListNode(1), cur.next cur.next ← ListNode(1) cur ← cur.next != cur.next == ...