98. Validate Binary Search Tree
来源:互联网 发布:淘宝充值平台关闭了 编辑:程序博客网 时间:2024/06/03 18:26
这题要多想,首相二叉平衡树的判断一定要从全局来看,分别大于小于某个数!!!,第二点,我被最大最小值卡了,所以就用了long long int然后改最大最小值,2刷刷好看一点的代码,思路要更加清晰
/** * 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 mark; void findit(TreeNode* root, long long int minn, long long int maxx){ if(root == NULL) return ; if(mark == false) return ; if(!(root -> val < maxx && root -> val > minn)){ mark = false; return ; } if(root -> left != NULL){ if(root -> left -> val >= root -> val){ mark = false; return ; } findit(root -> left, minn, root -> val); } if(root -> right != NULL){ if(root -> right -> val <= root -> val){ mark = false; return ; } findit(root -> right, root -> val, maxx); } return ; } bool isValidBST(TreeNode* root) { mark = true; if(root == NULL) return true; findit(root, -2147483649, 2147483648); return mark; }};
0 0
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 98. Validate Binary Search Tree
- 96. Unique Binary Search Trees
- 阿里巴巴 JAVA 开发手册-编程规约-格式规约
- 97. Interleaving String
- poj3114&3110-强连通图targan+spfa
- SpringMVC + MyBatis + Mysql + Redis(作为二级缓存) 配置
- 98. Validate Binary Search Tree
- 99. Recover Binary Search Tree
- DirectInput---输入输出控制利器
- 100. Same Tree
- 101. Symmetric Tree
- 字符串处理之文本规范化
- 102. Binary Tree Level Order Traversal
- [emacs]man mode
- 安卓开发——基于ViewPager的图片轮播