力扣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;
}
相关推荐
小欣加油1 小时前
leetcode56 合并区间
c++·算法·leetcode·职场和发展
lqqjuly1 小时前
前沿算法深度解析(二)
人工智能·算法·机器学习
wang09071 小时前
自己动手写一个spring之IOC_2
java·后端·spring
来杯@Java2 小时前
学生选课管理系统(基于springboot+vue前后端分离的项目)计算机毕业设计java
java·spring boot·spring·vue·毕业设计·maven·mybatis
徐小夕2 小时前
万字长文!千万级文档 RAG 知识库系统落地实践
前端·算法·github
不知名的老吴3 小时前
线程的生命周期之线程“插队“
java·开发语言·python
akunkuntaimei3 小时前
2026年高考数学各省真题及答案(完整版)
算法·高考
ANnianStriver3 小时前
PetLumina-02-后端开发与前后端联调
java·ai·sa-token
Hello:CodeWorld3 小时前
C 风格变参 vs C++ 变参模板:核心区别与选型指南
c语言·c++·算法