力扣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 分钟前
Spring Boot 的注解是如何生效的
java·spring boot·后端
爱读源码的大都督10 分钟前
挑战一下,用Java手写Transformer,先手写QKV,能成功吗?
java·后端·程序员
华仔啊12 分钟前
面试官灵魂拷问:count(1)、count(*)、count(列)到底差在哪?MySQL 性能翻车现场
java·后端
用户03321266636715 分钟前
在Word 中插入页眉页脚:实用 Java 指南
java
奔跑吧邓邓子16 分钟前
【Java实战㊱】Spring Boot邂逅Redis:缓存加速的奇妙之旅
java·spring boot·redis·缓存·实战
杨杨杨大侠18 分钟前
Atlas-Event:高性能事件处理与监控系统
java·github·eventbus
杨杨杨大侠21 分钟前
Atlas Event:解锁事件驱动的潜能
java·github·eventbus
兴科Sinco25 分钟前
[leetcode 1]给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出和为目标值 target 的那两个整数[力扣]
python·算法·leetcode
失散1325 分钟前
分布式专题——4 大厂生产级Redis高并发分布式锁实战
java·redis·分布式·缓存·架构
沐怡旸26 分钟前
【算法--链表】138.随机链表的复制--通俗讲解
算法·面试