力扣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;
}
相关推荐
XR1234567881 分钟前
办公大楼组网选型决策树:TCO 与三大品牌优劣对比总结
算法·决策树·机器学习
摇滚侠6 分钟前
《SpringBoot 3:入门与应用实战》第 9 章 使用 WebMvc 开发应用 阅读笔记 2
java·spring boot·笔记
阳明山水17 分钟前
Mamba路径如何建模长程时序依赖
人工智能·深度学习·算法·机器学习·架构
technology_x26 分钟前
液冷超充站设备厂家哪家好?2026年功率与散热对比
java·开发语言
LayZhangStrive40 分钟前
Agent开发 - MCP Client使用MCP Server的几种方式(Spring AI)
java·spring ai·mcp
仓三1 小时前
从 Prompt Engineering 到 Context Engineering:2026 年 Agent 性能提升的隐藏杠杆
java·prompt·context
许彰午1 小时前
07-SqlBuilder六法
java·开发语言·低代码·架构
孙6903421 小时前
Spring 注入多例 Bean
java·spring
Jul1en_1 小时前
【Java 脚手架】封装通用工具类-3
java·开发语言·redis·缓存·ai·bootstrap·rabbitmq
_Narcissus_2 小时前
分治&递归
数据结构·c++·笔记·算法·leetcode·递归·分治