力扣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;
}
相关推荐
wuminyu5 小时前
专家视角看Java字节码加载与存储指令机制
java·linux·c语言·jvm·c++
MediaTea6 小时前
AI 术语通俗词典:C4.5 算法
人工智能·算法
Navigator_Z6 小时前
LeetCode //C - 1033. Moving Stones Until Consecutive
c语言·算法·leetcode
WBluuue6 小时前
数据结构与算法:莫队(一):普通莫队与带修莫队
c++·算法
callJJ6 小时前
Spring Data Redis 两种编程模型详解:同步 vs 响应式
java·spring boot·redis·python·spring
风筝在晴天搁浅6 小时前
n个六面的骰子,扔一次之后和为k的概率是多少?
算法
wbs_scy7 小时前
Linux线程同步与互斥(三):线程同步深度解析之POSIX 信号量与环形队列生产者消费者模型,从原理到源码彻底吃透
java·开发语言
MATLAB代码顾问8 小时前
Python实现蜂群算法优化TSP问题
开发语言·python·算法
代码飞天8 小时前
机器学习算法和函数整理——助力快速查阅
人工智能·算法·机器学习
jiushiapwojdap8 小时前
LU分解法求解线性方程组Matlab实现
数据结构·其他·算法·matlab