blob: 0785d47401f6ffb23210f9727fcaba1b055bdb10 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#include "leetcode.h"
class Solution {
public:
bool isValidBST(TreeNode *root) {
if (!root)
return true;
inOrder(root);
for (int i = 1; i < tree.size(); i++)
if (tree[i] <= tree[i - 1])
return false;
return true;
}
private:
vector<int> tree;
void inOrder(TreeNode *root) {
if (!root)
return;
inOrder(root->left);
tree.push_back(root->val);
inOrder(root->right);
}
};
|