Inorder Tree Walk for Java

  • 0
    public class Solution {
        private void inorder(TreeNode root, List<Integer> array){
            if(root == null) return;
            inorder(root.left, array);
            inorder(root.right, array);
        public boolean isValidBST(TreeNode root) {
            List<Integer> array = new ArrayList();
            inorder(root, array);
            for(int i = 1; i < array.size(); i++){
                if(array.get(i) <= array.get(i-1)) return false;
            return true;  

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.