力扣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;
}
相关推荐
怕浪猫1 小时前
RAG 面试 6 连问,从原理到优化全部覆盖
python·算法·面试
无线通信科研笔记1 小时前
IEEE TVT 2026 论文精读与完整复现|相位误差如何重塑近场 RIS 的幅相响应
论文阅读·人工智能·python·算法·论文笔记
daidaidaiyu2 小时前
ThingsBoard 集群的核心逻辑源码分析
java
mmmmath_32 小时前
二叉树の递归遍历
算法
All for pursuit.3 小时前
【位运算-1】338.比特位计数
数据结构·c++·算法·leetcode
我可能是个假开发3 小时前
FTP Unicode 文件名导致 `550` 的问题分析与解决方案
java·开发语言·spring
caoerzhong3 小时前
中小企业上 WMS 该先上哪几块:JeeWMS 开源 Java 仓库管理系统的分批上线清单
java·python·开源
小师兄吃牛肉3 小时前
C语言中的nullptr有必要吗
c语言·c++·算法
【JAVA】玩家4 小时前
Spring核心原理全解析:从零到生产实战
java·后端·spring
Wang's Blog4 小时前
Java框架 SpringCloud 快速入门: 实现 Feign 最佳实践(抽取方式)
java·spring cloud