力扣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;
}
相关推荐
代码or搬砖几秒前
MyBatisPlus讲解(二)
java·mybatis
sweet丶5 分钟前
iOS MMKV原理整理总结:比UserDefaults快100倍的存储方案是如何炼成的?
算法·架构
lcu11110 分钟前
Java 学习42:抽象
java
Mr.朱鹏17 分钟前
RocketMQ安装与部署指南
java·数据库·spring·oracle·maven·rocketmq·seata
雨中飘荡的记忆20 分钟前
Spring表达式详解:SpEL从入门到实战
java·spring
Coder-coco20 分钟前
个人健康管理|基于springboot+vue+个人健康管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端·mysql·论文
5***26221 小时前
Spring Boot问题总结
java·spring boot·后端
xkroy1 小时前
Spring Boot日志
java·spring boot·后端
云里雾里!1 小时前
力扣 209. 长度最小的子数组:滑动窗口解法完整解析
数据结构·算法·leetcode
n***F8751 小时前
【Spring Boot】SpringBoot自动装配-Import
java·spring boot·后端