力扣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;
}
相关推荐
AM越.20 分钟前
Java设计模式详解--装饰器设计模式(含uml图)
java·设计模式·uml
59803541537 分钟前
【java工具类】小数、整数转中文大写
android·java·开发语言
JIngJaneIL1 小时前
基于java + vue个人博客系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
某林2121 小时前
基于SLAM Toolbox的移动机器人激光建图算法原理与工程实现
stm32·嵌入式硬件·算法·slam
吃喝不愁霸王餐APP开发者1 小时前
Java后端服务在对接全国性霸王餐API时的多数据中心部署与就近调用策略
java·开发语言
从心归零1 小时前
springboot-jpa的批量更新方法
java·spring boot·spring
修炼地1 小时前
代码随想录算法训练营第四十三天 | 图论理论基础、深搜理论基础、卡码网98. 所有可达路径、797. 所有可能的路径、广搜理论基础
算法·深度优先·图论
iAkuya1 小时前
(leetcode)力扣100 23反转链表(迭代||递归)
算法·leetcode·链表
这周也會开心1 小时前
128陷阱,==与equals区别
java·开发语言
剪一朵云爱着1 小时前
PAT 1095 Cars on Campus
算法·pat考试