Easiest c++ code


  • -1
    P

    class Solution {
    public:
    void in(TreeNode root,vector<int> &v)
    {
    if(root!=NULL)
    {
    in(root->left,v);
    v.push_back(root->val);
    in(root->right,v);
    }
    }
    bool isValidBST(TreeNode
    root) {
    if(root==NULL||(root->left==NULL&&root->right==NULL))
    return true;
    int i;
    vector<int> v;
    in(root,v);
    for(i=0;i<v.size()-1;i++)
    if(v[i]>=v[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.