Skip to content

Commit dff60ca

Browse files
committed
Add solution #897
1 parent e6d96c8 commit dff60ca

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@
707707
894|[All Possible Full Binary Trees](./0894-all-possible-full-binary-trees.js)|Medium|
708708
895|[Maximum Frequency Stack](./0895-maximum-frequency-stack.js)|Hard|
709709
896|[Monotonic Array](./0896-monotonic-array.js)|Easy|
710+
897|[Increasing Order Search Tree](./0897-increasing-order-search-tree.js)|Easy|
710711
901|[Online Stock Span](./0901-online-stock-span.js)|Medium|
711712
905|[Sort Array By Parity](./0905-sort-array-by-parity.js)|Easy|
712713
909|[Snakes and Ladders](./0909-snakes-and-ladders.js)|Medium|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* 897. Increasing Order Search Tree
3+
* https://leetcode.com/problems/increasing-order-search-tree/
4+
* Difficulty: Easy
5+
*
6+
* Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost
7+
* node in the tree is now the root of the tree, and every node has no left child and only one
8+
* right child.
9+
*/
10+
11+
/**
12+
* Definition for a binary tree node.
13+
* function TreeNode(val, left, right) {
14+
* this.val = (val===undefined ? 0 : val)
15+
* this.left = (left===undefined ? null : left)
16+
* this.right = (right===undefined ? null : right)
17+
* }
18+
*/
19+
/**
20+
* @param {TreeNode} root
21+
* @return {TreeNode}
22+
*/
23+
var increasingBST = function(root) {
24+
const result = new TreeNode(0);
25+
let current = result;
26+
27+
inorderTraversal(root);
28+
return result.right;
29+
30+
function inorderTraversal(node) {
31+
if (!node) return;
32+
33+
inorderTraversal(node.left);
34+
current.right = new TreeNode(node.val);
35+
current = current.right;
36+
inorderTraversal(node.right);
37+
}
38+
};

0 commit comments

Comments
 (0)