力扣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;
}
相关推荐
JiNan.YouQuan.Soft5 分钟前
数值计算引擎:计算固体力学
人工智能·算法·机器学习
抠脚小弟13 分钟前
Spring Cache 使用详解:从入门到实战
java·spring
和裕15 分钟前
光伏储能定制加强型瓦楞纸箱:降低组件运输隐裂率与售后损耗的核心价值
大数据·运维·网络·人工智能·算法
ZGG00323 分钟前
MySQL 索引详解:B+ 树、聚簇索引与最左前缀
java·数据库·mysql
萧瑟余晖33 分钟前
Java深入解析篇五十四之对象模型详解
java·开发语言
Pointer Pursuit35 分钟前
C++11特性(二)
前端·c++·算法
lvwangshu37 分钟前
数位 DP 进阶
算法·动态规划
她的男孩42 分钟前
一个开源低代码框架的协作 SPI 是怎么设计的 ForgeAdmin 拆解 + 实战接入新平台
后端·算法·架构
张文是假的啊1 小时前
Java | record | Controller逻辑
java·开发语言
勿忘,瞬间1 小时前
Mybatis高阶
java·数据库·mybatis