Floating-Point Error
- 2023.07.24
- Programming Techniques / Tools
- FloatingPointError
ε Epsilon Python float_info.epsilon 2.220446049250313e-16 #FloatingPointError
ε 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 ...
https://leetcode.com/contest/biweekly-contest-109/problems/visit-array-positions-to-maximize-score/ Solution Time Complexity: O(len(nums)) Space Complexity: O(1) (The input and output generally do not ...
https://leetcode.com/contest/biweekly-contest-109/problems/ways-to-express-an-integer-as-sum-of-powers/ Solution 當你需要的是出現的次數而無關順序時 ⇒ 使用 list Counter Time Complexity: O() Space Complexity: O() (The inp ...
計算value出現的次數 list.count(value) string.count(value, start, end)
Traversal 遍歷 (Using Binary Tree) 請參考:Binary Tree 二元樹 – Traversal 遍歷 範例 Leetcode # 439. Ternary Expression Parser Using Stack 一般來說,優先度相同時,優先順序從左至右 而當優先順序從右至左時,要改為逆序存取 (範例:Leetcode # 439. Ternary ...