力扣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;
}
相关推荐
Sam09272 小时前
【AI 算法精讲 16】BPE 分词:从字节对到子词
人工智能·python·算法·ai
LJHclasstore_luo2 小时前
【题解】WebGoC 102683.大雨过后
算法·goc编程
MrZhao4002 小时前
Agent 如何持续工作:任务持久化、后台执行与定时唤醒
算法
用户701720739002 小时前
密码学之分组密码
算法
MrZhao4002 小时前
Agent 长上下文处理机制:Context Compact 与 Memory 的协同
算法
要开心吖ZSH2 小时前
处方物流信息同步优化:从 36 秒到亚秒级的踩坑记录
java·数据库·mysql·性能优化
Wang's Blog2 小时前
JavaWeb快速入门: MyBatis入门与实战
java·mybatis
h_a_o777oah2 小时前
【动态规划】区间 DP :三层循环逻辑与模板实现细节(洛谷 P1880)
c++·算法·动态规划·acm·区间dp·化环为链·石子合并
从此以后自律2 小时前
迪杰斯特拉
算法