力扣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;
}
相关推荐
geovindu4 小时前
python:Logistic Regression
开发语言·后端·python·算法
摇滚侠4 小时前
《On Java 中文版 基础卷》阅读笔记 内部类 21
java·开发语言·笔记
geovindu5 小时前
python: Random Forest
开发语言·后端·python·算法·随机森林
凌冰_6 小时前
数据结构 - 线性结构(三)
java·数据结构·算法·软件工程
拂拉氏6 小时前
【知识讲解】 数据结构与算法-树状数组的认识
数据结构·算法·树状数组
Rain的Java大神之路8 小时前
Spring AI 2.0 GA 深度复盘:Java 后端做 AI 的分水岭,到底画在哪?
java·后端·aigc
饮水桶_T8 小时前
C++ STL00 | 六大核心组件协作框架 笔记
开发语言·算法·百度·facebook·新浪微博
如夏倾城9 小时前
进程状态模型详解:从三态、五态到 Linux 状态码映射
java·linux·服务器
小南家的青蛙10 小时前
JVM 参数调优实战指南
java·jvm