Skip to content

Commit

Permalink
update 104 java, progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed May 14, 2024
1 parent 9fb61ef commit 5450914
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@
095| [Unique Binary Search Trees II](https://leetcode.com/problems/unique-binary-search-trees-ii/) |[Python](./leetcode_python/Recursion/unique-binary-search-trees-ii.py) | _O(4^n / n^(3/2)_ | _O(4^n / n^(3/2)_ | Medium |recursion, BST, amazon, google, apple| AGAIN!!! (1)(good trick)
098| [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/)|[Python](./leetcode_python/Recursion/validate-binary-search-tree.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/Recursion/ValidateBinarySearchTree.java)| _O(n)_ | _O(1)_ | Medium |Curated Top 75, recursion, bfs, dfs,`BST`,`M$`,`amazon`, `fb`| AGAIN****************** (11)
100| [Same Tree](https://leetcode.com/problems/same-tree/) |[Python](./leetcode_python/Recursion/same-tree.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/Recursion/SameTree.java) | _O(n)_ | _O(h)_| Easy|Curated Top 75, recursion, dfs, bfs, `good basic`,`amazon`| OK****** (5) (but again)
104| [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/)| [Python](./leetcode_python/Recursion/maximum-depth-of-binary-tree.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/Recursion/MaximumDepthOfBinaryTree.java) | _O(n)_ | _O(h)_ | Easy |Curated Top 75, DFS, BFS, good basic,`amazon`, LC 111| OK****** (3) (but again)
104| [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/)| [Python](./leetcode_python/Recursion/maximum-depth-of-binary-tree.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/Recursion/MaximumDepthOfBinaryTree.java) | _O(n)_ | _O(h)_ | Easy |Curated Top 75, DFS, BFS, good basic,`amazon`, LC 111| OK******** (4) (but again)
105| [Construct Binary Tree from Preorder and Inorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | [Python](./leetcode_python/Recursion/construct-binary-tree-from-preorder-and-inorder-traversal.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/Recursion/ConstructBinaryTreeFromPreorderAndInorderTraversal.java) | _O(n)_ | _O(n)_ | Medium |Curated Top 75, `trick`, check # 106,`BST`,`M$`, `fb`| AGAIN********* (9)
106| [Construct Binary Tree from Inorder and Postorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | [Python](./leetcode_python/Recursion/construct-binary-tree-from-inorder-and-postorder-traversal.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/Recursion/ConstructBinaryTreeFromInorderAndPostorderTraversal.java) | _O(n)_ | _O(n)_ | Medium |`trick`,check # 105,`BST`,`M$`, `fb`| AGAIN******* (6)
108| [Convert Sorted Array to Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/) | [Python](./leetcode_python/Recursion/convert-sorted-array-to-binary-search-tree.py) | _O(n)_ | _O(logn)_ | Medium | `good concept`| AGAIN*
Expand Down
3 changes: 2 additions & 1 deletion data/progress.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
20240514: 105,106(todo)
20240515: 104
20240514: 105,106
20240513: 242,235
20240512: 371
20240511: 121,252
Expand Down
22 changes: 11 additions & 11 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
2024-07-08 -> ['105,106(todo)']
2024-07-08 -> ['105,106']
2024-07-07 -> ['242,235']
2024-07-06 -> ['371']
2024-07-05 -> ['121,252']
2024-07-04 -> ['125']
2024-06-17 -> ['105,106(todo)']
2024-06-17 -> ['105,106']
2024-06-16 -> ['242,235']
2024-06-15 -> ['371']
2024-06-14 -> ['121,252']
2024-06-13 -> ['125']
2024-06-04 -> ['105,106(todo)']
2024-06-04 -> ['105,106']
2024-06-03 -> ['242,235']
2024-06-02 -> ['371']
2024-06-01 -> ['121,252']
2024-05-31 -> ['125']
2024-05-27 -> ['105,106(todo)']
2024-05-27 -> ['105,106']
2024-05-26 -> ['242,235']
2024-05-25 -> ['371']
2024-05-24 -> ['121,252']
2024-05-23 -> ['125']
2024-05-22 -> ['105,106(todo)']
2024-05-22 -> ['105,106']
2024-05-21 -> ['242,235']
2024-05-20 -> ['371']
2024-05-19 -> ['105,106(todo)', '121,252']
2024-05-19 -> ['105,106', '121,252']
2024-05-18 -> ['242,235', '125']
2024-05-17 -> ['105,106(todo)', '371']
2024-05-16 -> ['105,106(todo)', '242,235', '121,252']
2024-05-15 -> ['105,106(todo)', '242,235', '371', '125']
2024-05-17 -> ['105,106', '371']
2024-05-16 -> ['105,106', '242,235', '121,252']
2024-05-15 -> ['105,106', '242,235', '371', '125']
2024-05-14 -> ['242,235', '371', '121,252']
2024-05-13 -> ['371', '121,252', '125']
2024-05-12 -> ['121,252', '125']
Expand Down Expand Up @@ -347,7 +347,7 @@
2022-10-11 -> ['489']
2022-10-10 -> ['489']
2022-10-09 -> ['052', '240']
2022-10-08 -> ['912', '095', '104']
2022-10-08 -> ['104', '912', '095']
2022-10-07 -> ['700,070']
2022-10-06 -> ['052']
2022-10-04 -> ['052']
Expand All @@ -363,7 +363,7 @@
2022-09-20 -> ['240', '912']
2022-09-19 -> ['240', '912']
2022-09-18 -> ['912', '779']
2022-09-17 -> ['095', '104']
2022-09-17 -> ['104', '095']
2022-09-16 -> ['700,070']
2022-09-12 -> ['095']
2022-09-10 -> ['779']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,34 @@ public int maxDepth(TreeNode root) {
// return 1;
// }

/** NOTE !!! we get max left, right depth first, then return bigger one as final answer */
int leftD = maxDepth(root.left) + 1;
int rightD = maxDepth(root.right) + 1;

return Math.max(leftD, rightD);
}


// V0'
// NOTE !!! below is wrong, we should get max left, right depth first, then compare them
// public int maxDepth(TreeNode root) {
//
// if (root == null){
// return 0;
// }
//
// if (root.left != null){
// return 1 + this.maxDepth(root.left);
// }
//
// if (root.right != null){
// return 1 + this.maxDepth(root.right);
// }
//
// return Math.max(this.maxDepth(root.left), this.maxDepth(root.right));
// }


// V0''
// IDEA : RECURSIVE
public int maxDepth_1(TreeNode root) {

Expand Down
16 changes: 16 additions & 0 deletions leetcode_java/src/main/java/dev/workspace3.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,22 @@ public TreeNode buildTree(int[] inorder, int[] postorder) {
return root;
}

// LC 104
// DFS
public int maxDepth(TreeNode root) {

if (root == null){
return 0;
}

if (root.left == null && root.right == null){
return 1;
}

int leftDepth = this.maxDepth(root.left) + 1;
int rightDepth = this.maxDepth(root.right) + 1;

return Math.max(leftDepth, rightDepth);
}

}

0 comments on commit 5450914

Please sign in to comment.