力扣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;
}
相关推荐
北风toto3 分钟前
研发效能与后端核心技术全景指南:从CI/CD到共性组件实战
java·开发语言·ci/cd
01二进制代码漫游日记6 分钟前
C++基础入门速通
java·开发语言·c++
Herbert_hwt8 分钟前
第六章 Java深入理解接口、函数式接口与lambda表达式
java·开发语言·算法
API快乐传递者24 分钟前
电商竞品分析接口实战指南:从数据采集到决策洞察的全链路方案
java·python
君君思密达32 分钟前
LeetCode Hot 100 题目详解-滑动窗口
算法·leetcode·职场和发展
程序员黑豆8 小时前
Java类型推断完全指南:从var到菱形运算符,掌握使用限制与最佳实践
java·前端·ai编程
GreenTea9 小时前
深度解读 Anthropic 多智能体报告:更强的模型 ≠ 更好的协调
前端·后端·算法
风流 少年9 小时前
Spring AI 2.0:Memory
java·后端·spring
码匠许师傅9 小时前
【C++ 面试真题】聊聊 C++ 的移动语义与右值引用
java·c++·面试
小席是个热心肠9 小时前
AI相关的自我学习
java·人工智能·学习