力扣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;
}
相关推荐
代码飞天7 分钟前
算法与数据结构之又臭又长的表
数据结构·算法
workflower10 分钟前
如何使用设计模式-误区
java·开发语言·设计模式·集成测试·软件工程·需求分析·软件需求
A923A12 分钟前
【洛谷刷题 | 第七天】
算法·模拟·洛谷
故事和你9112 分钟前
洛谷-入门4-数组3
开发语言·数据结构·c++·算法·动态规划·图论
人道领域13 分钟前
Day | 12 【苍穹外卖 :导出Excel数据表】
java·后端·sql·servlet·mvc·intellij-idea
毕设源码-朱学姐17 分钟前
【开题答辩全过程】以 校园超市购物系统为例,包含答辩的问题和答案
java
玉树临风ives17 分钟前
atcoder ABC 451 题解
c++·算法·atcoder
_日拱一卒17 分钟前
LeetCode:和为K的子数组
算法·leetcode·职场和发展
zs宝来了19 分钟前
Spring IoC 容器初始化全链路深度解析:从 BeanFactory 到 refresh() 的底层真相
java·后端·spring·ioc·源码解析·java后端
周可温84120 分钟前
动手学RAG
算法