力扣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;
}
相关推荐
Shaoshing几秒前
Serializable
java
圣保罗的大教堂5 分钟前
leetcode 2778. 特殊元素平方和 简单
leetcode
UIU11414 分钟前
P1115 最大子段和
c++·算法
垆边人似月.16 分钟前
华为题:零钱兑换
算法·华为
wuminyu16 分钟前
ZGC染色指针在虚拟线程stackChunkOop上的并发屏障全景分析
java·linux·c语言·jvm·c++
蜗牛互联网28 分钟前
Python Agent 工具调用:审批令牌、参数白名单和累计预算
java·开发语言·人工智能·windows·后端·python
哦虎!30 分钟前
【JavaEE】网络编程套接字
java
Wang's Blog32 分钟前
Java 项目实战: 交友项目 - SpringCloud 整合 Dubbo 的方案概述
java·spring cloud·交友
Logic10133 分钟前
C语言/数据结构组合数学题解:数字好排列计数——质数倍数分类与阶乘取模
c语言·数据结构·算法·组合数学·时间复杂度·排列·取模运算
imDwAaY1 小时前
程序里的地址是真实内存地址吗?从虚拟内存到地址转换
java·linux·服务器