力扣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;
}
相关推荐
会编程的土豆4 分钟前
洛谷题单入门1 顺序结构
数据结构·算法·golang
小小小米粒7 分钟前
Collection单列集合、Map(Key - Value)双列集合,多继承实现。
java·开发语言·windows
生信碱移7 分钟前
PACells:这个方法可以鉴定疾病/预后相关的重要细胞亚群,作者提供的代码流程可以学习起来了,甚至兼容转录组与 ATAC 两种数据类型!
人工智能·学习·算法·机器学习·数据挖掘·数据分析·r语言
智者知已应修善业27 分钟前
【51单片机中的打飞机设计】2023-8-25
c++·经验分享·笔记·算法·51单片机
摇滚侠37 分钟前
expdp 查看帮助
java·数据库·oracle
:1211 小时前
java基础
java·开发语言
圣保罗的大教堂2 小时前
leetcode 1855. 下标对中的最大距离 中等
leetcode
曹牧2 小时前
Spring:@RequestMapping注解,匹配的顺序与上下文无关
java·后端·spring
daixin88482 小时前
cursor无法正常使用gpt5.5等模型解决方案
java·redis·cursor
智者知已应修善业3 小时前
【51单片机按键调节占空比3位数码管显示】2023-8-24
c++·经验分享·笔记·算法·51单片机