力扣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 小时前
Python基础学习:文件操作详解(打开、读取、写入与路径)
java·服务器·python
Dreams_l1 小时前
基于SpringBoot实现的抽奖系统(四)
java·spring boot·后端
这个昵称不容易2 小时前
SpringBoot 网上订餐系统设计与实现:80 个 Java 文件、91 个接口,附真实运行截图
java·springboot·毕设
Helix2502 小时前
JDK异常处理最佳实践:受检异常、非受检异常、try-catch-finally与全局异常处理完整指南
java·开发语言·jdk·异常处理·全局异常·自定义异常·try-catch
小O的算法实验室3 小时前
SEVC,城市灾害环境下应急物流的帕累托归档引导式多目标路径规划
算法
维克兜率天3 小时前
【维克】布林带:通道类指标的“量化基石“
人工智能·python·算法
风落青芜3 小时前
C++入门:类和对象(二)
开发语言·数据结构·c++·算法
木雷坞4 小时前
n8n Docker 读不到 CSV,先分清宿主机目录和容器路径
java·docker·容器
wuyk5554 小时前
AI 时代的嵌入式该怎么学-11-C不是语法是对内存的显式建模
c语言·开发语言·stm32·单片机·嵌入式硬件·mcu·算法