力扣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;
}
相关推荐
p***q7813 小时前
SpringBoot实战:高效实现API限流策略
java·spring boot·后端
3***161014 小时前
【JavaEE】Spring Boot 项目创建
java·spring boot·java-ee
6***v41714 小时前
VScode 开发 Springboot 程序
java·spring boot·后端
STY_fish_201214 小时前
P11855 [CSP-J2022 山东] 部署
算法·图论·差分
myw07120514 小时前
湘大头歌程-Ride to Office练习笔记
c语言·数据结构·笔记·算法
t***316514 小时前
SpringBoot中自定义Starter
java·spring boot·后端
H_BB14 小时前
算法详解:滑动窗口机制
数据结构·c++·算法·滑动窗口
Zero-Talent14 小时前
“栈” 算法
算法
橘子编程14 小时前
经典排序算法全解析
java·算法·排序算法
waeng_luo14 小时前
【鸿蒙开发实战】智能数据洞察服务:待回礼分析与关系维护建议算法
算法·ai编程·鸿蒙