力扣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;
}
相关推荐
ytttr8732 小时前
隐马尔可夫模型(HMM)MATLAB实现范例
开发语言·算法·matlab
野生的码农2 小时前
码农的妇产科实习记录
android·java·人工智能
AlenTech3 小时前
160. 相交链表 - 力扣(LeetCode)
数据结构·leetcode·链表
点云SLAM3 小时前
凸优化(Convex Optimization)理论(1)
人工智能·算法·slam·数学原理·凸优化·数值优化理论·机器人应用
jz_ddk3 小时前
[学习] 卫星导航的码相位与载波相位计算
学习·算法·gps·gnss·北斗
毕设源码-赖学姐3 小时前
【开题答辩全过程】以 高校人才培养方案管理系统的设计与实现为例,包含答辩的问题和答案
java
放荡不羁的野指针4 小时前
leetcode150题-动态规划
算法·动态规划
sin_hielo4 小时前
leetcode 1161(BFS)
数据结构·算法·leetcode
一起努力啊~4 小时前
算法刷题-二分查找
java·数据结构·算法
小途软件4 小时前
高校宿舍访客预约管理平台开发
java·人工智能·pytorch·python·深度学习·语言模型