Skip to content

Commit 4c10c78

Browse files
solves increasig bst
1 parent e3f766a commit 4c10c78

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
| 892 | [Surface Area of 3D Shapes](https://leetcode.com/problems/surface-area-of-3d-shapes) | [![Java](assets/java.png)](src/SurfaceAreaOf3DShapes.java) |
244244
| 893 | [Groups of Special Equivalent Strings](https://leetcode.com/problems/groups-of-special-equivalent-strings) | |
245245
| 896 | [Monotonic Array](https://leetcode.com/problems/monotonic-array) | [![Java](assets/java.png)](src/MonotonicArray.java) |
246-
| 897 | [Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree) | |
246+
| 897 | [Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree) | [![Java](assets/java.png)](src/IncreasingOrderSearchTree.java) |
247247
| 905 | [Sort Array by Parity](https://leetcode.com/problems/sort-array-by-parity) | |
248248
| 908 | [Smallest Range I](https://leetcode.com/problems/smallest-range-i) | |
249249
| 914 | [X of a kind in a Deck of Cards](https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards) | |

Diff for: src/IncreasingOrderSearchTree.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class IncreasingOrderSearchTree {
2+
TreeNode current;
3+
4+
public TreeNode increasingBST(TreeNode root) {
5+
if (root == null) return null;
6+
TreeNode result = new TreeNode();
7+
current = result;
8+
inOrderTraversal(root);
9+
return result.right;
10+
}
11+
12+
private void inOrderTraversal(TreeNode root) {
13+
if (root == null) return;
14+
inOrderTraversal(root.left);
15+
current.right = new TreeNode(root.val);
16+
current = current.right;
17+
inOrderTraversal(root.right);
18+
}
19+
}

0 commit comments

Comments
 (0)