BFS 和 DFS 為用以在 tree 中搜尋特定 node 的演算法 Breadth-First Search 廣度優先搜尋 Depth-First Search 深度優先搜尋 相關文章:Binary Tree 二元樹 Iterative Implementation BFS:使用 Queue Template queue = collections.deque([root]) w ...
https://leetcode.com/problems/valid-anagram/ Solution Time Complexity: O(max(len(s), len(t))) Space Complexity: O(max(len(s), len(t))) (The input and output generally do not count towards the space co ...
https://leetcode.com/problems/sort-characters-by-frequency/ Solution Time Complexity: O(len(s)) Space Complexity: O(len(s)) (The input and output generally do not count towards the space complexity.) ...
Asymptotic notations are the mathematical notations that describes the limiting behavior of a function when the argument tends towards a particular value or infinity. O(Big O) Notation \begin{align} & ...
全等於 同餘 $$ a \equiv b \ (mod m) \quad 即 \quad a \ \% \ m == b \ \% \ m $$
https://leetcode.com/problems/search-a-2d-matrix/ Solution m := len(matrix) n := len(matrix[0]) Time Complexity: O(m + log(n)) > O(log(m) + log(n)) = O(log(m * n)) Space Complexity: O(1) (The input ...
https://leetcode.com/problems/longest-palindrome/ Solution Palindrome: 回文 Time Complexity: O(len(s)) Space Complexity: O(1) (The input and output generally do not count towards the space complexity.) ...
https://leetcode.com/problems/determine-if-two-strings-are-close/ Solution Time Complexity: O(len(word1)) Space Complexity: O(1) ※ 英文字母只有26個,所以 sort 在時間上將會花費 O(26 * log(26)) = O(1) 在 Space Complexity ...
https://leetcode.com/problems/determine-if-string-halves-are-alike/ Solution 注意: s[:len(s) // 2] s[:len(s) / 2] ( len(s) / 2 不是整數,不能作為 index ) Time Complexity: O(len(s)) Space Complexity: O(1) (The i ...
$$ \mathop{arg\_min}\limits_{x \in S} := \{ x \in S : f(s) \geq f(x) \text{for all } s \in S \} $$ $$ \mathop{arg\_max}\limits_{x \in S} := \{ x \in S : f(s) \leq f(x) \text{for all } s \in S \} $$