力扣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;
}
相关推荐
Keven_11几秒前
算法札记:有限差分
算法
忙里偷闲学python5 分钟前
GK2A 林火蔓延预报算法说明
算法
我是伪码农13 分钟前
11.21程序设计
数据结构·算法
IManiy15 分钟前
AgentScope Java 2.0(四)上下文、状态与中间件
java
Tisfy1 小时前
LeetCode 3561.移除相邻字符:栈(相邻相消)
算法·leetcode·字符串·题解·栈·相邻相消
战6171 小时前
Python 基础算法:三种排序、二分查找与递归
开发语言·python·算法
青山木1 小时前
JVM 类加载全解:Class 文件结构、加载链接初始化与双亲委派
java·jvm·后端·类加载·双亲委派机制
灯澜忆梦2 小时前
并查集(Disjoint Set Union,DSU)
数据结构·算法
Nazarick2 小时前
从 fetch 到 then:Demo在线订单系统 Ajax 回调的逐帧拆解
java·javascript·ajax·web
智购科技自动售货机厂家2 小时前
自动售货机外设接口与总线设计实战:串口、CAN 与 GPIO 的分工~YH
java·大数据·服务器·数据库·人工智能·单片机·嵌入式硬件