力扣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;
}
相关推荐
想吃火锅10051 分钟前
【leetcode】56.合并区间js
算法·leetcode·职场和发展
imuliuliang3 分钟前
可合并堆在多任务调度中的优势与实现技巧7
算法
学究天人4 分钟前
数学公理体系大全:Comprehensive Collection of Mathematical Axiom Systems(卷6)
网络·算法·数学建模·动态规划·几何学·图论·拓扑学
wabs66610 分钟前
关于动态规划【力扣72.编辑距离的思考】
算法·leetcode·动态规划
FREEDOM_X10 分钟前
Linux 多线程编程——总结
java·linux·运维·ubuntu
tmlx3I08119 分钟前
Tomcat的架构设计和启动过程详解
java·tomcat
weixin_4223293127 分钟前
AgentScope Java 项目入门 & Builder 深度解读
java·开发语言·人工智能
用户3332397688427 分钟前
我做了一个 RepoMind:让 AI 写架构前,先去看看真实开源项目
算法
shepherd12630 分钟前
一次把 Spring MVC 文件上传参数“查没了”的排查:multipart、Filter 与 request body 的连环坑
java·后端·spring·mvc
宠友信息40 分钟前
Spring Boot与异步审核构建仿小红书源码内容发布全流程
java·数据库·spring boot·redis·mysql·oracle·uni-app