Skip to content

Commit

Permalink
update cheatsheet, progress
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Jun 6, 2024
1 parent 8572a16 commit bbffb86
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@
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*
109| [Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/) | [Python](./leetcode_python/Recursion/convert-sorted-array-to-binary-search-tree.py) | _O(n)_ | _O(logn)_ | Medium |`list`,`BST`,`good concept`, `fb`| AGAIN*** (3)
110| [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/) | [Python](./leetcode_python/Recursion/balanced-binary-tree.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/Recursion/BalancedBinaryTree.java) | _O(n)_| _O(h)_ | Easy |`good trick`,`dfs`,`amazon` ,`fb`, google, top-down, bottom-up recursion| AGAIN********** (5)(MUST)
110| [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/) | [Python](./leetcode_python/Recursion/balanced-binary-tree.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/Recursion/BalancedBinaryTree.java) | _O(n)_| _O(h)_ | Easy |`good trick`,`dfs`,`amazon` ,`fb`, google, top-down, bottom-up recursion| AGAIN************ (6)(MUST)
111| [Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree/)|[Python](./leetcode_python/Recursion/minimum-depth-of-binary-tree.py), [Java](./leetcode_java/src/main/java/LeetCodeJava/Recursion/MinimumDepthOfBinaryTree.java)| _O(n)_ | _O(h)_ | Easy |`good basic`,`dfs`,`BST`,`amazon`,`fb`, LC 104| AGAIN******** (5)
114| [Flatten Binary Tree to Linked List](https://leetcode.com/problems/flatten-binary-tree-to-linked-list/)| [Python](./leetcode_python/Recursion/flatten-binary-tree-to-linked-list.py)| _O(n)_ | _O(h)_ | Medium |`BST`, `dfs`, `M$`, `fb`| AGAIN**** (4)
116| [Populating Next Right Pointers in Each Node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node/)| [Python](./leetcode_python/Recursion/populating-next-right-pointers-in-each-node.py) | _O(n)_ | _O(1)_ | Medium |bfs, dfs, tree, recursion ,AGAIN,`fb`, amazon| AGAIN****** (5)
Expand Down
2 changes: 1 addition & 1 deletion data/progress.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
20240606: 206,143,138(again),141,needcode_tree,226,104
20240606: 206,143,138(again),141,needcode_tree,226,104,110(again!!!)
20240605: 150,22(again),739(again!!!),needcode_linkedlist
20240604: 567(todo),needcode_array_hash,needcode_sliding_window,567(again),needcode_stack,155(again)
20240603: 146,460,582(ok*),139(ok),322(todo)
Expand Down
18 changes: 9 additions & 9 deletions data/to_review.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2024-07-31 -> ['206,143,138(again),141,needcode_tree,226,104']
2024-07-31 -> ['206,143,138(again),141,needcode_tree,226,104,110(again!!!)']
2024-07-30 -> ['150,22(again),739(again!!!),needcode_linkedlist']
2024-07-29 -> ['567(todo),needcode_array_hash,needcode_sliding_window,567(again),needcode_stack,155(again)']
2024-07-28 -> ['146,460,582(ok*),139(ok),322(todo)']
Expand All @@ -18,7 +18,7 @@
2024-07-13 -> ['207,79,206,213,198']
2024-07-12 -> ['212(todo),211,338,208(again)']
2024-07-11 -> ['347,253(todo),91(todo),217']
2024-07-10 -> ['206,143,138(again),141,needcode_tree,226,104', '226,98,253(todo)']
2024-07-10 -> ['206,143,138(again),141,needcode_tree,226,104,110(again!!!)', '226,98,253(todo)']
2024-07-09 -> ['150,22(again),739(again!!!),needcode_linkedlist', '104,230,102,100']
2024-07-08 -> ['567(todo),needcode_array_hash,needcode_sliding_window,567(again),needcode_stack,155(again)', '105,106']
2024-07-07 -> ['146,460,582(ok*),139(ok),322(todo)', '242,235']
Expand All @@ -30,27 +30,27 @@
2024-06-30 -> ['21,20,19,271,269']
2024-06-29 -> ['417(again),33,153,152']
2024-06-28 -> ['424,297(todo),295(todo),39']
2024-06-27 -> ['206,143,138(again),141,needcode_tree,226,104', '55,54(todo),53(again),435(again),49,48(todo),300(again)']
2024-06-27 -> ['206,143,138(again),141,needcode_tree,226,104,110(again!!!)', '55,54(todo),53(again),435(again),49,48(todo),300(again)']
2024-06-26 -> ['150,22(again),739(again!!!),needcode_linkedlist', '56']
2024-06-25 -> ['567(todo),needcode_array_hash,needcode_sliding_window,567(again),needcode_stack,155(again)', '62,572,57']
2024-06-24 -> ['146,460,582(ok*),139(ok),322(todo)', '322,191,190']
2024-06-23 -> ['127,742(again),133(again),207(ok*),261(ok)', '73,200,70,323(again)']
2024-06-22 -> ['128,261', '207,79,206,213,198']
2024-06-21 -> ['005,003(again)', '212(todo),211,338,208(again)']
2024-06-20 -> ['347,253(todo),91(todo),217']
2024-06-19 -> ['206,143,138(again),141,needcode_tree,226,104', '11,647,261(again),133(again)', '226,98,253(todo)']
2024-06-19 -> ['206,143,138(again),141,needcode_tree,226,104,110(again!!!)', '11,647,261(again),133(again)', '226,98,253(todo)']
2024-06-18 -> ['150,22(again),739(again!!!),needcode_linkedlist', '143,15,268,141,139', '104,230,102,100']
2024-06-17 -> ['567(todo),needcode_array_hash,needcode_sliding_window,567(again),needcode_stack,155(again)', '21,20,19,271,269', '105,106']
2024-06-16 -> ['146,460,582(ok*),139(ok),322(todo)', '417(again),33,153,152', '242,235']
2024-06-15 -> ['127,742(again),133(again),207(ok*),261(ok)', '424,297(todo),295(todo),39', '371']
2024-06-14 -> ['206,143,138(again),141,needcode_tree,226,104', '128,261', '55,54(todo),53(again),435(again),49,48(todo),300(again)', '121,252']
2024-06-14 -> ['206,143,138(again),141,needcode_tree,226,104,110(again!!!)', '128,261', '55,54(todo),53(again),435(again),49,48(todo),300(again)', '121,252']
2024-06-13 -> ['150,22(again),739(again!!!),needcode_linkedlist', '005,003(again)', '56', '125']
2024-06-12 -> ['567(todo),needcode_array_hash,needcode_sliding_window,567(again),needcode_stack,155(again)', '62,572,57']
2024-06-11 -> ['206,143,138(again),141,needcode_tree,226,104', '146,460,582(ok*),139(ok),322(todo)', '11,647,261(again),133(again)', '322,191,190']
2024-06-11 -> ['206,143,138(again),141,needcode_tree,226,104,110(again!!!)', '146,460,582(ok*),139(ok),322(todo)', '11,647,261(again),133(again)', '322,191,190']
2024-06-10 -> ['150,22(again),739(again!!!),needcode_linkedlist', '127,742(again),133(again),207(ok*),261(ok)', '143,15,268,141,139', '73,200,70,323(again)']
2024-06-09 -> ['206,143,138(again),141,needcode_tree,226,104', '567(todo),needcode_array_hash,needcode_sliding_window,567(again),needcode_stack,155(again)', '128,261', '21,20,19,271,269', '207,79,206,213,198']
2024-06-08 -> ['206,143,138(again),141,needcode_tree,226,104', '150,22(again),739(again!!!),needcode_linkedlist', '146,460,582(ok*),139(ok),322(todo)', '005,003(again)', '417(again),33,153,152', '212(todo),211,338,208(again)']
2024-06-07 -> ['206,143,138(again),141,needcode_tree,226,104', '150,22(again),739(again!!!),needcode_linkedlist', '567(todo),needcode_array_hash,needcode_sliding_window,567(again),needcode_stack,155(again)', '127,742(again),133(again),207(ok*),261(ok)', '424,297(todo),295(todo),39', '347,253(todo),91(todo),217']
2024-06-09 -> ['206,143,138(again),141,needcode_tree,226,104,110(again!!!)', '567(todo),needcode_array_hash,needcode_sliding_window,567(again),needcode_stack,155(again)', '128,261', '21,20,19,271,269', '207,79,206,213,198']
2024-06-08 -> ['206,143,138(again),141,needcode_tree,226,104,110(again!!!)', '150,22(again),739(again!!!),needcode_linkedlist', '146,460,582(ok*),139(ok),322(todo)', '005,003(again)', '417(again),33,153,152', '212(todo),211,338,208(again)']
2024-06-07 -> ['206,143,138(again),141,needcode_tree,226,104,110(again!!!)', '150,22(again),739(again!!!),needcode_linkedlist', '567(todo),needcode_array_hash,needcode_sliding_window,567(again),needcode_stack,155(again)', '127,742(again),133(again),207(ok*),261(ok)', '424,297(todo),295(todo),39', '347,253(todo),91(todo),217']
2024-06-06 -> ['150,22(again),739(again!!!),needcode_linkedlist', '567(todo),needcode_array_hash,needcode_sliding_window,567(again),needcode_stack,155(again)', '146,460,582(ok*),139(ok),322(todo)', '128,261', '11,647,261(again),133(again)', '55,54(todo),53(again),435(again),49,48(todo),300(again)', '226,98,253(todo)']
2024-06-05 -> ['567(todo),needcode_array_hash,needcode_sliding_window,567(again),needcode_stack,155(again)', '146,460,582(ok*),139(ok),322(todo)', '127,742(again),133(again),207(ok*),261(ok)', '005,003(again)', '143,15,268,141,139', '56', '104,230,102,100']
2024-06-04 -> ['146,460,582(ok*),139(ok),322(todo)', '127,742(again),133(again),207(ok*),261(ok)', '128,261', '21,20,19,271,269', '62,572,57', '105,106']
Expand Down
30 changes: 0 additions & 30 deletions doc/cheatsheet/binary_tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,33 +300,3 @@ class BSTIterator(object):
"""
return self.stack.pop()
```

### 2-6) Balanced Binary Tree
```python
# LC 110. Balanced Binary Tree
# V0
# https://blog.csdn.net/coder_orz/article/details/51335758
class Solution(object):
def isBalanced(self, root):
"""
:type root: TreeNode
:rtype: bool
"""
if root == None:
return True

self.getAllDepth(root)

left_depth = root.left.val if root.left else 0
right_depth = root.right.val if root.right else 0
if abs(left_depth - right_depth) <= 1:
return self.isBalanced(root.left) and self.isBalanced(root.right)
else:
return False

def getAllDepth(self, root):
if root == None:
return 0
root.val = 1 + max(self.getAllDepth(root.left), self.getAllDepth(root.right))
return root.val
```
32 changes: 32 additions & 0 deletions doc/cheatsheet/tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ root = TreeNode(int(s))

#### 1-1-3 -1) Get Maximum depth
- LC 104 : Maximum Depth of Binary Tree
- LC 110 : Balanced Binary Tree

```java
// java
Expand Down Expand Up @@ -1671,4 +1672,35 @@ class Solution:

return numGoodNodes;
}
```

### 2-19) Balanced Binary Tree
```java
// java
// LC 110

// V1
// IDEA : TOP DOWN RECURSION
// https://leetcode.com/problems/balanced-binary-tree/editorial/
// Recursively obtain the height of a tree. An empty tree has -1 height
private int height(TreeNode root) {
// An empty tree has height -1
if (root == null) {
return -1;
}
return 1 + Math.max(height(root.left), height(root.right));
}

public boolean isBalanced(TreeNode root) {
// An empty tree satisfies the definition of a balanced tree
if (root == null) {
return true;
}

// Check if subtrees have height within 1. If they do, check if the
// subtrees are balanced
return Math.abs(height(root.left) - height(root.right)) < 2
&& isBalanced(root.left)
&& isBalanced(root.right);
}
```
9 changes: 9 additions & 0 deletions leetcode_java/src/main/java/dev/workSpace4.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.stream.Collectors;

public class workSpace4 {
int abc = 100;
public static void main(String[] args) {


Expand Down Expand Up @@ -241,6 +242,14 @@ public static void main(String[] args) {
System.out.println(y);
}


workSpace4 wp = new workSpace4();
wp.myFunc();

}

private void myFunc(){
System.out.println("abc = " + abc);
}

}
63 changes: 63 additions & 0 deletions leetcode_java/src/main/java/dev/workspace3.java
Original file line number Diff line number Diff line change
Expand Up @@ -3954,5 +3954,68 @@ public int maxDepth(TreeNode root) {

}

// LC 543
public int diameterOfBinaryTree(TreeNode root) {

return 0;
}

// LC 110
// 6.55
// Given a binary tree, determine if it is
// height-balanced
//.
/**
* A height-balanced binary tree
* is a binary tree in which the depth of the
* two subtrees of every node never differs by more than one.
*/
public boolean isBalanced(TreeNode root) {

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

// ?
return Math.abs(this.height(root.left) - this.height(root.right)) < 2
&& isBalanced(root.left)
&& isBalanced(root.right);
}

private int height(TreeNode root) {
// An empty tree has height -1
if (root == null) {
return -1;
}
return 1 + Math.max(height(root.left), height(root.right));
}


// public boolean checkSub(TreeNode root){
// if (root.left == null && root.right == null){
// return true;
// }
//
// if (root.left == null && root.right != null){
// if (root.right.right != null || root.right.left != null){
// return false;
// }
// }
//
// if (root.right == null && root.left != null){
// if (root.left.right != null || root.left.left != null){
// return false;
// }
// }
//
// if (root.right != null && root.left != null){
//// if (root.left.right != null || root.left.left != null){
//// return false;
//// }
// }
//
// return false;
// }


}

0 comments on commit bbffb86

Please sign in to comment.