zoukankan      html  css  js  c++  java
  • 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 = 1;
            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 = 0;
            }
            if(root->right) dfs(root->right,maxnum,flag);
        }
    };

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

  • 相关阅读:
    Linux命令
    Linux目录说明
    python推导式
    python公共方法
    python集合
    python字典
    python元组
    python列表
    python字符串常用操作方法
    C语言编译过程
  • 原文地址:https://www.cnblogs.com/cunyusup/p/10582263.html
Copyright © 2011-2022 走看看