力扣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;
}
相关推荐
百锦再2 分钟前
Java中的日期时间API详解:从Date、Calendar到现代时间体系
java·开发语言·spring boot·struts·spring cloud·junit·kafka
踩坑记录4 分钟前
leetcode hot100 78. 子集 递归回溯 medium 位运算法
leetcode
Frostnova丶14 分钟前
LeetCode 761. 特殊的二进制字符串
算法·leetcode
A懿轩A19 分钟前
【Java 基础编程】Java 枚举与注解从零到一:Enum 用法 + 常用注解 + 自定义注解实战
java·开发语言·python
不吃橘子的橘猫32 分钟前
《集成电路设计》复习资料3(电路模拟与SPICE)
学习·算法·集成电路·仿真·半导体
m0_5312371735 分钟前
C语言-函数递归
算法
tuokuac35 分钟前
MyBatis-Plus调用getEntity()触发异常
java·mybatis
mjhcsp37 分钟前
C++Z 函数超详细解析
c++·算法·z 函数
_但为君故_1 小时前
优化Tomcat的JVM内存
java·jvm·tomcat
yaoxin5211231 小时前
328. Java Stream API - 使用 Optional 的正确姿势:为何、何时、如何使用
java·开发语言