Determine whether the balanced binary tree

Given a binary tree, it is determined whether the balanced binary tree;

Balanced binary tree is called a left node is less than the root node, the root node less than the right,

We were on a balanced binary tree traversal sequence, the result is a ascending, our problem-solving ideas is this another way

code show as below:

public Boolean isValidBST (the TreeNode the root) { 
        Stack <the TreeNode> Stack = new new Stack <> ();
         Long tmp = of Long.MIN_VALUE;
         the while (stack.isEmpty () = the root ||!! null ) {
             the while (= the root! null ) { 
                stack.push (the root); 
                the root = root.left; 
            } 
            iF (! stack.isEmpty ()) { 
                the root = stack.pop ();
                 // determine whether the current node is a value greater than that of the stack node 
                IF (root.val <= tmp) {
                    return false;
                }
                tmp = root.val * 1L;

                root = root.right;
            }
        }
        return true;
    }

 

Guess you like

Origin www.cnblogs.com/du001011/p/11241640.html