力扣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;
}
相关推荐
Code_Solitude6 小时前
C语言动态内存 + 柔性数组 + 数组名退化
c语言·算法·柔性数组
上海潭龙东海科技有限公司6 小时前
客运站管控之动态孪生技术方案(新增一屏管控模块
数据仓库·人工智能·算法·重构·动态规划
文丑颜不良啊7 小时前
LeetCode2821~2840题目解析
java·leetcode
apcipot_rain8 小时前
C++转Java日记(10)
java·开发语言
简 洁 冬冬8 小时前
泛型方法写法全面辨析:从「能编译」到「能跑」到「能用」
java·泛型
YLCHUP9 小时前
【思维&图论建模】题解:债权(debt)_图论_建模_思路转化_思维题目_C++算法竞赛
c++·笔记·算法·数学建模·贪心算法·深度优先·图论
LGL6030A9 小时前
Java学习历程31——初识Spring Boot
java·spring boot·学习
思麟呀9 小时前
背包DP(01背包+完全背包)
c++·算法
笑容掩饰我的失落10 小时前
区块链从小白到精通(七):Solidity 语法精讲——数据类型、函数、修饰器与事件
算法·区块链·php·智能合约·哈希算法
Lansonli11 小时前
大数据Spark(八十八):Spark任务资源之Standalone集群测试
java·服务器·spark