[Algorithm] Recursion 遞迴
定義 Recursion is a method of solving a computational problem where the solution depends on solutions to smaller instances of the same problem. Recursion solves such recursive problems by using function ...
定義 Recursion is a method of solving a computational problem where the solution depends on solutions to smaller instances of the same problem. Recursion solves such recursive problems by using function ...
Stack Memory 使用 stack 後進先出 (Last In First Out) 的概念 用以保存區域變數 (loval variables) 使用暫時性的記憶體空間, 一旦任務完成(函式執行結束後),會自動被抹去 Heap Memory 保存全域變數 (global variables)
https://leetcode.com/problems/binary-tree-maximum-path-sum/ Solution Time Complexity: O(len(tree)) Space Complexity: O(len(tree)) (The input and output generally do not count towards the space complex ...
https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree First Solution Time Complexity: O(len(tree)) Space Complexity: O((len(tree)) ^ 2) (The input and output generally do not co ...
https://leetcode.com/problems/insert-into-a-binary-search-tree/ Solution Time Complexity: O(log(len(tree))) Space Complexity: O(1) (The input and output generally do not count towards the space comple ...
https://leetcode.com/problems/symmetric-tree/ Solution Time Complexity: O(len(tree)) Space Complexity: O(len(tree)) (The input and output generally do not count towards the space complexity.) class So ...
https://leetcode.com/problems/path-sum/ Solution Return True if the tree has a root-to-leaf path Time Complexity: O(len(tree)) Space Complexity: O(len(tree)) (The input and output generally do not cou ...
https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph Solution: Disjoint Set Union (DSU) Time Complexity: O() Space Complexity: O() (The input and output generally do not ...
https://leetcode.com/problems/number-of-islands/ Solution: Disjoint Set Union (DSU) Time Complexity: O(len(grid) * len(grid[0])) Space Complexity: O(len(grid) * len(grid[0])) (The input and output gen ...
https://leetcode.com/problems/leaf-similar-trees/ Solution Time Complexity: O(len(tree1 + tree2)) Space Complexity: O(len(tree1 + tree2)) (The input and output generally do not count towards the space ...