力扣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;
}
相关推荐
随意起个昵称7 小时前
区间dp-基础题目1(石子合并)
算法·动态规划
吞下星星的少年·-·7 小时前
线段树模板
算法
橙淮7 小时前
并发编程(六)
java·jvm
段一凡-华北理工大学7 小时前
2026 高炉炼铁智能化技术全景与演进路径~系列文章11:演进路径与行业未来
大数据·网络·人工智能·算法·工业智能体·高炉炼铁智能化
拽着尾巴的鱼儿7 小时前
springboot openfeign 自定义feign 接口重试机制
java·spring boot·后端
白露与泡影7 小时前
2026大厂Java面试题大全!牛客网最新版
java·开发语言
叶小鸡8 小时前
小鸡玩算法-力扣HOT100-多维动态规划
算法·leetcode·动态规划
星马梦缘8 小时前
aaaaa
数据结构·c++·算法
EntyIU8 小时前
JVM内存与GC笔记
java·jvm·笔记
XS0301069 小时前
并发编程 六
java·后端