package com.fishercoder.solutions;

import java.util.Stack;

/**
 * 255. Verify Preorder Sequence in Binary Search Tree
 * 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> stack = new Stack();
        for (int p : preorder) {
            if (p < low) {
                return false;
            }
            while (!stack.empty() && p > stack.peek()) {
                low = stack.pop();
            }
            stack.push(p);
        }
        return true;
    }

}

@@ -58,333 +58,69 @@
 k;%0A%0A
-/**%0A * 255. Verify Preorder Sequence in Binary Search Tree%0A * Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary search tree.%0A * You may assume each number in the sequence is unique.%0A%0A Follow up:%0A Could you do it using only constant space complexity?%0A */%0Apublic class _255 %7B%0A%0A
+public class _255 %7B%0A%0A    public static class Solution1 %7B%0A    
     
@@ -175,16 +175,20 @@
         
+ 
+   
 int low 
@@ -208,16 +208,20 @@
 _VALUE;%0A
+    
         
@@ -252,24 +252,28 @@
 ew Stack();%0A
+    
         for 
@@ -305,16 +305,20 @@
         
+    
 if (p %3C 
@@ -336,24 +336,28 @@
             
+    
 return false
@@ -358,16 +358,20 @@
  false;%0A
+    
         
@@ -388,16 +388,20 @@
         
+    
 while (!
@@ -453,16 +453,20 @@
         
+    
 low = st
@@ -480,34 +480,42 @@
 ();%0A            
+   
+ 
 %7D%0A
+    
             stac
@@ -533,26 +533,33 @@
         
-%7D%0A
+    %7D%0A   
         
 return t
@@ -546,24 +546,25 @@
 %0A           
+ 
 return true;
@@ -564,16 +564,26 @@
 n true;%0A
+        %7D%0A
     %7D%0A%0A%7D

refactor 255