力扣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;
}
相关推荐
程序猿_极客41 分钟前
【2025 年最新版】Java JDK 安装与环境配置教程(附图文超详细,Windows+macOS 通用)
java·开发语言·windows·macos·jdk
猫头虎1 小时前
macOS 双开/多开微信WeChat完整教程(支持 4.X 及以上版本)
java·vscode·macos·微信·编辑器·mac·脚本
一个不知名程序员www4 小时前
算法学习入门 --- 哈希表和unordered_map、unordered_set(C++)
c++·算法
二哈喇子!4 小时前
Java开发工具——IDEA(修改全局配置,提升工作效率)
java·编辑器·intellij-idea
强子感冒了4 小时前
Java网络编程学习笔记,从网络编程三要素到TCP/UDP协议
java·网络·学习
二哈喇子!4 小时前
SpringBoot项目右上角选择ProjectNameApplication的配置
java·spring boot
Sarvartha4 小时前
C++ STL 栈的便捷使用
c++·算法
sin22014 小时前
MyBatis的执行流程
java·开发语言·mybatis
二哈喇子!4 小时前
基于Spring Boot框架的车库停车管理系统的设计与实现
java·spring boot·后端·计算机毕业设计
二哈喇子!4 小时前
基于Spring Boot框架的网络游戏虚拟交易平台的设计与实现
java·springboot·毕设项目