力扣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;
}
相关推荐
小bo波1 天前
枚举实战
java·设计模式·枚举·后端开发·代码重构
8Qi81 天前
LeetCode 213:打家劫舍 II(House Robber II)—— 题解 ✅
算法·leetcode·职场和发展·动态规划
夜微凉41 天前
三、Spring
java·后端·spring
三品吉他手会点灯1 天前
C语言学习笔记 - 44.运算符和表达式 - 运算符2 - 除法与取余运算符
c语言·开发语言·笔记·算法
橘右今1 天前
2026 Java后端高频面试宝典
java·开发语言·面试
乐迪信息1 天前
乐迪信息:AI算法盒子实时识别船舶烟雾与火焰异常
大数据·人工智能·算法·安全·目标跟踪
J-Tony111 天前
【JVM】根可达算法
jvm·算法
艾iYYY1 天前
string 类的模拟实现
android·服务器·c语言·c++·算法
Lsk_Smion1 天前
力扣实训 _ [75].颜色分类 _ 杨辉三角
数据结构·算法·leetcode