力扣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;
}
相关推荐
小陈phd21 小时前
深入理解agent学习笔记(一)——现代agent介绍
人工智能·算法
程序猿在线码字21 小时前
数据结构前置知识(java版)
java
圣保罗的大教堂21 小时前
leetcode 1665. 完成所有任务的最少初始能量 中等
leetcode
步行cgn21 小时前
Spring 基于 XML 的自动装配:byType 详解
java·后端·spring
边境悍匪21 小时前
蜗牛学苑 Java 智能体学习 Day46|贯穿项目 2 思维导图复盘
java·开发语言·vue.js·学习·spring
智慧物业老杨1 天前
物业日常巡查的数智化重构:从“打卡式巡检“到“闭环式风控“
android·java·人工智能·系统架构·rxjava
晴天的雨.9921 天前
【C++算法】和为s的两个数
开发语言·数据结构·c++·算法
步行cgn1 天前
Spring c 命名空间注入详解
java·后端·spring
明月_清风1 天前
Maven 到底是什么?一篇文章搞懂 Java 项目构建与依赖管理
java·后端·maven
aramae1 天前
MySQL复合查询(8)
java·c语言·开发语言·后端·算法