Leetcode 98

/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool isValidBST(TreeNode* root) {
vector<int> res;
int flag = ;
long num = LONG_MIN;
dfs(root,num,flag);
return flag;
} void dfs(TreeNode* root,long& maxnum,int& flag){
if(root == NULL) return;
if(root->left) dfs(root->left,maxnum,flag);
if(root->val > maxnum){
maxnum = root->val;
}
else{
flag = ;
}
if(root->right) dfs(root->right,maxnum,flag);
}
};

__卡边界有点恶心,改成LONG就好了

上一篇:FDR校正


下一篇:Educational Codeforces Round 10 D. Nested Segments 【树状数组区间更新 + 离散化 + stl】