力扣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;
}
相关推荐
WBluuue11 小时前
Codeforces 1087 Div2(ABCDEF)
c++·算法
Kiling_070411 小时前
Java多态、final与抽象类:面向对象编程进阶指南
java·开发语言
better_liang12 小时前
每日Java面试场景题知识点之-MySQL索引
java·数据库·mysql·性能优化·索引
Yzzz-F12 小时前
2025 ICPC武汉邀请赛 G [根号分治 容斥原理+DP]
算法
abant212 小时前
leetcode 114 二叉树变链表
算法·leetcode·链表
tankeven12 小时前
HJ165 小红的优惠券
c++·算法
Aktx20FNz12 小时前
一文学习 Spring AOP 源码全过程
java·学习·spring
Nyarlathotep011312 小时前
ThreadLocal
java·后端
先积累问题,再逐次解决12 小时前
快速幂优美算法
算法