力扣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;
}
相关推荐
M-Robots echo16 分钟前
轻量化裁剪方案解析:M-Robots 模块化构建,适配高低端各类机器人硬件平台
java·机器人·ros·开源社区·atomgit·m-robots
不可求~1 小时前
多模型路由怎么落地:把任务分流写进项目的最小实现
java·前端·数据库
数模竞赛Paid answer1 小时前
2026年中青杯数学建模A题数学建模论文智能评估系统与多智能体优化方法求解全过程论文及程序
算法·数学建模·中青杯
银-豆豆1 小时前
数据结构与算法-动态规划、回溯与贪心
算法·动态规划
mldong2 小时前
用 DDD 设计工作流引擎:聚合根与充血模型
java·架构
mqiqe3 小时前
AgentScope Java Harness:4. 双层记忆系统 让 Agent 拥有真正的“长期大脑“
java·开发语言
伍一513 小时前
03-文件管理模块-一个看似简单的模块藏着多少细节
java·ruoyi·若依
想吃火锅10053 小时前
【leetcode】200. 岛屿数量
算法·leetcode·职场和发展
gugucoding3 小时前
46. 【Java】JUC并发工具:让并发更简单
java·开发语言
Nil2083 小时前
leetcode 54螺旋矩阵
算法·leetcode·矩阵