|
2 | 2 |
|
3 | 3 | importcom.fishercoder.common.classes.TreeNode;
|
4 | 4 |
|
5 |
| -/** |
6 |
| - * 1008. Construct Binary Search Tree from Preorder Traversal |
7 |
| - * |
8 |
| - * Return the root node of a binary search tree that matches the given preorder traversal. |
9 |
| - * (Recall that a binary search tree is a binary tree where for every node, any descendant of node.left has a value < node.val, and any descendant of node.right has a value > node.val. |
10 |
| - * Also recall that a preorder traversal displays the value of the node first, then traverses node.left, then traverses node.right.) |
11 |
| - * |
12 |
| - * Example 1: |
13 |
| - * |
14 |
| - * Input: [8,5,1,7,10,12] |
15 |
| - * Output: [8,5,10,1,7,null,12] |
16 |
| - * |
17 |
| - * 8 |
18 |
| - * / \ |
19 |
| - * 5 10 |
20 |
| - * / \ \ |
21 |
| - * 1 7 12 |
22 |
| - * |
23 |
| - * Note: |
24 |
| - * |
25 |
| - * 1 <= preorder.length <= 100 |
26 |
| - * The values of preorder are distinct. |
27 |
| - * */ |
28 | 5 | publicclass_1008 {
|
29 | 6 | publicstaticclassSolution1 {
|
30 |
| -/**credit: https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal/discuss/252232/JavaC%2B%2BPython-O(N)-Solution*/ |
| 7 | +/** |
| 8 | + * credit: https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal/discuss/252232/JavaC%2B%2BPython-O(N)-Solution |
| 9 | + */ |
31 | 10 | inti =0;
|
32 | 11 |
|
33 | 12 | publicTreeNodebstFromPreorder(int[]preorder) {
|
|