力扣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;
}
相关推荐
这不小天嘛6 小时前
JAVA八股——J集合篇
java·开发语言
ysu_03147 小时前
05 | 持久化撤销提示非核心功能
算法·游戏程序
浮沉9878 小时前
二分查找算法概述&通用模板
算法
Keven_119 小时前
算法札记:SPFA判负环算法的证明
算法
什巳9 小时前
JAVA练习278- 和为 K 的子数组
java·学习·算法·leetcode
豆瓣鸡9 小时前
RocketMQ学习-Spring Boot消息实践
java·spring boot·rocketmq
Jerry9 小时前
LeetCode 347. 前 K 个高频元素
算法
wuqingshun3141599 小时前
说一下mysql的覆盖索引
java