二叉搜索树中序遍历后为升序
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
List<TreeNode> nodeList = new ArrayList<>();
public boolean isValidBST(TreeNode root) {
inorder(root);
for(int i = 0; i < nodeList.size()-1; i++){
if(nodeList.get(i).val >= nodeList.get(i + 1).val){//不要忘了取具体的值
return false;
}
}
return true;
}
public void inorder(TreeNode root){
if(root == null){
return;
}
isValidBST(root.left);
nodeList.add(root);
isValidBST(root.right);
}
}