力扣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;
}
相关推荐
lueluelue472 小时前
LeetCode:链表
算法·leetcode·链表
橘子汽水1685 小时前
Leetcode 23,543合并K个升序链表,二叉树的直径
算法·leetcode·链表
huameinan狮子5 小时前
Adaboost算法原理与计算实例
算法
别怪我很水5 小时前
API中提供了VelocityTracker类用于计算触摸事件MotionEvent的速度,而其内部默认使用的方法就是最小二乘法,本 ...
算法·gitee·最小二乘法
都叫我大帅哥6 小时前
Java JJWT 完全指南:从入门到生产级实践
java
前端开发张小七7 小时前
Java 学习笔记 · 第一课:基础语法与核心概念
java·后端
ThsPool8 小时前
【ENVI二次开发学习整理 04】ENVI功能扩展与二次开发
java·前端·javascript
赤壁小虾8 小时前
【渲染流水线】[逐片元阶段]-[透明度测试]以UnityURP为例
java·前端·数据库
Re.不晚9 小时前
挑战做100道力扣算法- DAY1
算法·leetcode·职场和发展