-
Notifications
You must be signed in to change notification settings - Fork 288
/
Copy pathAC_dfs_n.cpp
42 lines (34 loc) · 856 Bytes
/
AC_dfs_n.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_dfs_n.cpp
* Create Date: 2015-03-03 14:02:59
* Descripton: Simulation.
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
// Definition for binary tree
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution {
private:
bool dfs(TreeNode *root, long long minval, long long maxval) {
if (root == NULL)
return true;
return root->val > minval &&
root->val < maxval &&
dfs(root->left, minval, root->val) &&
dfs(root->right, root->val, maxval);
}
public:
bool isValidBST(TreeNode *root) {
return dfs(root, (long long)INT_MIN - 1, (long long)INT_MAX + 1);
}
};
int main() {
return 0;
}