力扣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;
}
相关推荐
凤山老林1 小时前
04-Java JDK, JRE和JVM
java·开发语言·jvm
灵感__idea6 小时前
Hello 算法:贪心的世界
前端·javascript·算法
camellias_7 小时前
【无标题】
java·tomcat
咸鱼2.07 小时前
【java入门到放弃】需要背诵
java·开发语言
澈2078 小时前
深入浅出C++滑动窗口算法:原理、实现与实战应用详解
数据结构·c++·算法
椰猫子8 小时前
Java:异常(exception)
java·开发语言
ambition202428 小时前
从暴力搜索到理论最优:一道任务调度问题的完整算法演进历程
c语言·数据结构·c++·算法·贪心算法·深度优先
cmpxr_8 小时前
【C】原码和补码以及环形坐标取模算法
c语言·开发语言·算法
qiqsevenqiqiqiqi8 小时前
前缀和差分
算法·图论
代码旅人ing8 小时前
链表算法刷题指南
数据结构·算法·链表