力扣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;
}
相关推荐
9***Y4812 分钟前
Java开发工具IntelliJ IDEA技巧
java·开发语言·intellij-idea
Java爱好狂.21 分钟前
2025全年Java面试真题总结!
java·jvm·高并发·多线程·java面试·后端开发·java八股文
Charles_go40 分钟前
C#中级39、什么是依赖注入设计模式
java·设计模式·c#
ComplexPy43 分钟前
ZKMall-B2B2C Redission延时队列
java·redis
q***965843 分钟前
深入解析Spring Boot中的@ConfigurationProperties注解
java·spring boot·后端
java1234_小锋43 分钟前
讲讲Mybatis的一级、二级缓存?
java·开发语言·mybatis
e***87701 小时前
记录 idea 启动 tomcat 控制台输出乱码问题解决
java·tomcat·intellij-idea
发现你走远了1 小时前
2025 idea 指定配置环境运行springboot 设置active和env启动端口,多端口启动 (保姆级图文)
java·spring boot·intellij-idea
sanggou1 小时前
Java秒杀系统设计与实现
java
小年糕是糕手1 小时前
【C++】C++入门 -- 输入&输出、缺省参数
c语言·开发语言·数据结构·c++·算法·leetcode·排序算法