package com.fishercoder.solutions;

import java.util.Stack;

/**
 * Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary search tree.

 You may assume each number in the sequence is unique.

 Follow up:
 Could you do it using only constant space complexity?
 */
public class _255 {

    public boolean verifyPreorder(int[] preorder) {
        int low = Integer.MIN_VALUE;
        Stack<Integer> path = new Stack();
        for (int p : preorder) {
            if (p < low) {
                return false;
            }
            while (!path.empty() && p > path.peek()) {
                low = path.pop();
            }
            path.push(p);
        }
        return true;
    }

}

@@ -58,16 +58,71 @@
 k;%0A%0A/**%0A
+ * 255. Verify Preorder Sequence in Binary Search Tree%0A
  * Given
@@ -229,17 +229,18 @@
 h tree.%0A
-%0A
+ *
  You may
@@ -491,20 +491,21 @@
 nteger%3E 
-path
+stack
  = new S
@@ -636,20 +636,21 @@
 while (!
-path
+stack
 .empty()
@@ -657,20 +657,21 @@
  && p %3E 
-path
+stack
 .peek())
@@ -695,20 +695,21 @@
   low = 
-path
+stack
 .pop();%0A
@@ -738,12 +738,13 @@
     
-path
+stack
 .pus

refactor 255