File tree 2 files changed +39
-0
lines changed
2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 707
707
894|[ All Possible Full Binary Trees] ( ./0894-all-possible-full-binary-trees.js ) |Medium|
708
708
895|[ Maximum Frequency Stack] ( ./0895-maximum-frequency-stack.js ) |Hard|
709
709
896|[ Monotonic Array] ( ./0896-monotonic-array.js ) |Easy|
710
+ 897|[ Increasing Order Search Tree] ( ./0897-increasing-order-search-tree.js ) |Easy|
710
711
901|[ Online Stock Span] ( ./0901-online-stock-span.js ) |Medium|
711
712
905|[ Sort Array By Parity] ( ./0905-sort-array-by-parity.js ) |Easy|
712
713
909|[ Snakes and Ladders] ( ./0909-snakes-and-ladders.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments