力扣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;
}
相关推荐
pshdhx_albert1 小时前
AI agent实现打字机效果
java·http·ai编程
汀、人工智能2 小时前
[特殊字符] 第40课:二叉树最大深度
数据结构·算法·数据库架构·图论·bfs·二叉树最大深度
沉鱼.442 小时前
第十二届题目
java·前端·算法
赫瑞3 小时前
数据结构中的排列组合 —— Java实现
java·开发语言·数据结构
大熊背3 小时前
ISP Pipeline中Lv实现方式探究之三--lv计算定点实现
数据结构·算法·自动曝光·lv·isppipeline
西岸行者4 小时前
BF信号是如何多路合一的
算法
大熊背4 小时前
ISP Pipeline中Lv实现方式探究之一
算法·自动白平衡·自动曝光
周末也要写八哥4 小时前
多进程和多线程的特点和区别
java·开发语言·jvm
罗西的思考4 小时前
【OpenClaw】通过 Nanobot 源码学习架构---(5)Context
人工智能·算法·机器学习
惜茶5 小时前
vue+SpringBoot(前后端交互)
java·vue.js·spring boot