力扣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;
}
相关推荐
裕晟资质规划7 分钟前
三类涉密资质延续时限差异分析:军工60日与集成印制3个月的边界
java·服务器·前端·网络·安全
念念清晰8 分钟前
000-OpenJDK17 源码构建:MacOS环境(M芯片)
java·后端
Wang's Blog32 分钟前
Java 项目实战: 交友项目 - 百度人脸识别入门案例
java·百度·交友
erzong23140 分钟前
Linux操作系统:线程概念与控制
linux·算法
wuminyu1 小时前
JMM学习总结:深入理解happens-before关系
java·linux·c语言·jvm·c++
电商API_180079052471 小时前
反向海淘多币种结算:汇率该在哪个时点被冻结
java·开发语言·数据库·跨境电商·1688 api
Nil2081 小时前
leetcode 5最长回文子串
算法·leetcode·职场和发展
xxwl5851 小时前
区域赛分类题解
c++·笔记·学习·算法
m0_674571971 小时前
力扣 hot 100 python
python·算法·leetcode
开开心心就好2 小时前
多份文档怎么批量打印?支持多种格式
java·服务器·开发语言·pdf·ocr·散列表·启发式算法