力扣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;
}
相关推荐
phltxy21 小时前
C语言操作符详解
java·c语言·算法
aqiu1111111 天前
【LeetCode 902】最大为 N 的数字组合 - 详细题解与数位组合思路
数据结构·算法·leetcode·蓝桥杯·数位dp
步行cgn1 天前
@Configuration 详解:Spring 配置类的核心注解
java·后端·spring
sunshine22 girl1 天前
Java学习一 环境配置2 安装和基本使用Idea
java·学习·intellij-idea
辰烨chenye1 天前
LeetCode Hot 100 题解 · 哈希篇
算法·leetcode·哈希算法
罗西的思考1 天前
DreamZero 与 DreamDojo:世界模型与策略的分层协同综合分析与对比
人工智能·算法·机器学习
玖玥拾1 天前
LeetCode 219 存在重复元素 II
算法·leetcode·哈希算法·散列表
嘿嘿-661 天前
Windows 一键使用 GPT-6 Astra:Codex CLI 配置教程
java·人工智能·windows·gpt·chatgpt·web
知无不研1 天前
c语言中循环的介绍与简单应用
c语言·开发语言·算法·循环·for·while