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)) (若在長乘法乘算途中即做加法, ...
0-9 48-57 A-Z 65-90 a-z 97-122
https://leetcode.com/problems/confusing-number Solution 問題:n 是否顛倒後仍是一組數字並且不等於 n ? Time Complexity: O(log(n)) Space Complexity: O(1) (The input and output generally do not count towards the space compl ...
ε Epsilon Python float_info.epsilon 2.220446049250313e-16 #FloatingPointError
https://leetcode.com/problems/buddy-strings Solution 交換兩個 character 後 s 和 gaol 會一樣 ⇒ 回傳 True s 和 goal 只有在 i, j 的兩個 character 不一樣 (s[i] != goal[i] and s[j] != goal [j]), 且 s[i] = goal[j], s[j] = goal[i ...
https://leetcode.com/problems/powx-n Solution (Memoization) Time Complexity: O(log(n)) Space Complexity: O(log(n)) (The input and output generally do not count towards the space complexity.) class Sol ...
https://leetcode.com/problems/add-binary Solution Time Complexity: O(max(len(a), len(b)) Space Complexity: O(1) (The input and output generally do not count towards the space complexity.) class Soluti ...
The lowest common ancestor (LCA) (also called least common ancestor) of two nodes u and v in a tree or directed acyclic graph (DAG) T is the lowest (i.e. deepest) node that has both v and w as descend ...