力扣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;
}
相关推荐
凌冰_33 分钟前
数据结构 - 时间空间复杂度(一)
数据结构·算法·软件工程
武昌库里写JAVA43 分钟前
SpringBoot+Vue 项目介绍
java·javascript·git·sql·ai
Pniubi1 小时前
力扣2 . 两数相加
算法·leetcode·职场和发展
戴·菲瑜1 小时前
为什么PPO难以做出顶级棋类引擎
算法·博弈论·rl·ppo
学长毕设2 小时前
基于SpringBoot的儿童慈善捐赠管理系统-附源码
java·spring boot·后端
慧一居士2 小时前
@RestControllerAdvice 的注解作用和使用
java
学长毕设3 小时前
基于SpringBoot非遗文化展示与传播平台设计与实现-附源码
java·spring boot·后端
在所不辞兄4 小时前
为什么数字孪生驱动的产线标定需要在线更新机制,而不能一次标定后长期沿用?
人工智能·神经网络·其他·算法·机器学习
金銀銅鐵5 小时前
用 Swing 重做操作数栈演示
java·jvm·后端
琳少_5 小时前
java程序开发笔记
java·开发语言·数据库·笔记