力扣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;
}
相关推荐
CV_J2 小时前
安装kibana
java·elasticsearch·spring cloud·docker·容器
码农水水4 小时前
国家电网Java面试被问:TCP的BBR拥塞控制算法原理
java·开发语言·网络·分布式·面试·wpf
2013092416274 小时前
1968年 Hart, Nilsson, Raphael 《最小成本路径启发式确定的形式基础》A* 算法深度研究报告
人工智能·算法
如何原谅奋力过但无声4 小时前
【力扣-Python-滑动窗口经典题】567.字符串的排列 | 424.替换后的最长重复字符 | 76.最小覆盖子串
算法·leetcode
qq_336313934 小时前
java基础-网络编程-TCP
java·网络·tcp/ip
咕噜咕噜啦啦5 小时前
Java期末习题速通
java·开发语言
盐真卿5 小时前
python2
java·前端·javascript
玄冥剑尊5 小时前
贪心算法进阶
算法·贪心算法
玄冥剑尊5 小时前
贪心算法深化 I
算法·贪心算法
52Hz1185 小时前
力扣73.矩阵置零、54.螺旋矩阵、48.旋转图像
python·算法·leetcode·矩阵