[Python] f-string (String Formatting)
- 2023.07.27
- Python
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 ...
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 == ...
因為 Python 多重賦值 (Multiple Assignment) 時的計算順序導致的錯誤 Leetcode # 2. Add Two Numbers ⭐️ Leetcode # 206. Reverse Linked List 追加 node 適切的方式 使用 pre Leetcode # 206. Reverse Linked List 在迴圈繼續時才追加 Leetcode # 2. A ...
https://leetcode.com/problems/merge-two-sorted-lists Solution Time Complexity: O(len(list1) + len(list2)) Space Complexity: O(1) (The input and output generally do not count towards the space complexi ...
<table style=”border-style: none;” border=”1″> … </table> <td style=”border-color: #ffffff;“> … </td> 常用 Templete 1
https://leetcode.com/problems/ternary-expression-parser 三元條件運算子 Ternary Conditional Operator variable = condition ? value_if_true : value_if_false or condition ? expr1 : expr2 Solution (Stack) 根 ...
https://leetcode.com/problems/multiply-strings First Solution M := len(num1) N := len(num2) Time Complexity: O(M * N + N * (M + N)) = O(M * N + N ** 2) Space Complexity: O(N * (M + N)) (若在長乘法乘算途中即做加法, ...