[LeetCode 265] Count Univalue Subtrees
来源:互联网 发布:linux grub无法用命令 编辑:程序博客网 时间:2024/04/29 16:53
题目:
Given a binary tree, count the number of uni-value subtrees.
A Uni-value subtree means all nodes of the subtree have the same value.
For example:
Given binary tree,
5 / \ 1 5 / \ \ 5 5 5
return 4
.
class Solution {public:int count;int countUnivalSubtrees(TreeNode* root) {if(root==NULL) return 0;count=0;unival(root);return count;}bool unival(TreeNode* root) {bool left=true,right=true;if(root->left) {left=unival(root->left);if(root->val!=root->left->val) left=false;}if(root->right) {right=unival(root->right);if(root->val!=root->right->val) right=false;}if(left&&right) {count++;return true;}return false;}};
0 0
- [LeetCode 265] Count Univalue Subtrees
- Leetcode: Count Univalue Subtrees
- *LeetCode-Count Univalue Subtrees
- LeetCode 题解(265) : Count Univalue Subtrees
- Leetcode 250Count Univalue Subtrees
- LeetCode 250. Count Univalue Subtrees
- [leetcode] 250. Count Univalue Subtrees 解题报告
- Leetcode 250. Count Univalue Subtrees (Medium) (cpp)
- [Leetcode] 250. Count Univalue Subtrees 解题报告
- [LeetCode250]Count Univalue Subtrees
- Count Univalue Subtrees
- Count Univalue Subtrees
- 250. Count Univalue Subtrees
- 250. Count Univalue Subtrees
- LeetCode 250. Count Univalue Subtrees(单值子树)
- [leetcode 250]Count Univalue Subtrees ------元素都相同的子树个数
- [leetcode] 687. Longest Univalue Path
- leetcode 687. Longest Univalue Path
- 对计算机组成原理的考研归纳(不断更新中)
- Android实现计时与倒计时(限时抢购)的几种方法
- 快速搭建python机器学习开发环境(Windows)
- ReactJS[未完待续]
- iOS-UILable总结
- [LeetCode 265] Count Univalue Subtrees
- 第三周练习 随机函数应用于游戏-猜数字
- Spring MVC 中的 RedirectAttribute
- mysql数据库函数用法简析
- KD树的python实践
- Common Lisp笔记(2)
- 字符串编辑距离的几种实现
- 让人癫狂的24号,请你慢点离开
- 封装一个简单的轮播图