力扣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;
}
相关推荐
REDcker2 小时前
Linux OverlayFS详解
java·linux·运维
玖釉-2 小时前
下一个排列:从字典序到原地算法的完整推导
数据结构·c++·windows·算法
IronMurphy2 小时前
【算法五十】62. 不同路径
算法
Royzst2 小时前
xml知识点
java·服务器·前端
影寂ldy2 小时前
C#一维数组
算法
鱼鳞_2 小时前
苍穹外卖-Day08(缓存套餐)
java·redis·缓存
过期动态2 小时前
【LeetCode 热题 100】移动零
java·数据结构·算法·leetcode·职场和发展·rabbitmq
计算机安禾3 小时前
【算法分析与设计】第10篇:下界理论与NP完全性初步
大数据·人工智能·算法
sinat_255487814 小时前
IDEA:查找文件/类
java·ide·设计模式·intellij-idea