AC C++ use vector+inorder


  • 0
    class Solution {
    vector<int> t;
    public:
    	void travel(TreeNode* root)
    	{
    		if(!root) return;
    		travel(root->left);
    		t.push_back(root->val);
    		travel(root->right);
    	}
        bool isValidBST(TreeNode* root) {
            travel(root);
            if(t.size()<2) return true;
            for(int i=1; i<t.size();i++)
            {
            	if(t[i-1]>=t[i]) return false;
            }
            return true;
        }
    };
    

Log in to reply
 

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