力扣965 单值二叉树

Here is the code for you to see directly, however, there are a few points.

1. in the second 'if' clause, note the existence of the root node

2. Once there is at least one false value among the serval judgment values, the result after the && operation is false.

复制代码
bool isUnivalTree(struct TreeNode* root) {
	if (root == NULL)
		return true;
	if (root->left && root->left->val!= root->val)
		return false;
	if (root->right&&root->right->val!=root->val)
		return false;
	bool a = isUnivalTree(root->left) && isUnivalTree(root->right);
	return a;
}
相关推荐
小梦爱安全1 分钟前
Ansible剧本1
java·网络·ansible
周末也要写八哥5 分钟前
最长递增子序列典型应用题目详解
数据结构·算法
pupudawang25 分钟前
Spring Boot 热部署
java·spring boot·后端
我登哥MVP27 分钟前
【SpringMVC笔记】 - 9 - 异常处理器
java·spring boot·spring·servlet·tomcat·maven
不会写DN32 分钟前
为什么map查找时间复杂度是O(1)?
算法·哈希算法·散列表
下地种菜小叶33 分钟前
Spring Boot 2.x 升级 3.x / 4.x 怎么做?一次讲清 JDK、Jakarta、依赖兼容与上线策略
java·spring boot·后端
iiiiyu34 分钟前
常用API(StringJoiner类 & Math类 & System类)
java·大数据·开发语言·数据结构·编程语言
始三角龙35 分钟前
LeetCode hoot 100 -- 找到字符串中的所有字母异位词
算法·leetcode·职场和发展
abant240 分钟前
leetcode 45 跳跃问题2 很难的贪心
算法·leetcode·职场和发展
小糯米60141 分钟前
C语言指针3
c语言·数据结构·算法