力扣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;
}
相关推荐
8Qi82 小时前
回文子串(Palindromic Substrings)—— 题解
算法·leetcode·职场和发展·动态规划
二月夜4 小时前
剖析Java正则表达式回溯问题
java·正则表达式
xuhaoyu_cpp_java5 小时前
项目学习(三)分页查询
java·经验分享·笔记·学习
程序员二叉5 小时前
【Java】集合面试全套精讲|HashMap/ArrayList高频考点完整版
java·面试·哈希算法
cfm_29145 小时前
JVM GC垃圾回收初步了解
java·开发语言·jvm
心之伊始6 小时前
LangChain4j RAG 实战:Java 后端如何把本地文档接入 Embedding 检索链路
java·架构·源码分析·csdn
许彰午6 小时前
17_synchronized关键字深度解析
java·开发语言
小宋加油啊7 小时前
机械臂抓取物体 PVN3D算法调研学习
学习·算法·3d
lqqjuly7 小时前
前沿算法深度解析(一)
算法