力扣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;
}
相关推荐
zzzll11117 分钟前
SpringBoot 入门与实践指南
java·spring boot·后端
科学实验家7 分钟前
贪心算法:分饼干
算法·贪心算法
额,不知道写啥。24 分钟前
题解:P16710 愿望
数据结构·算法
库玛西38 分钟前
快速幂算法全景总结图:从“愚公移山”到“细胞分裂”
c语言·c++·笔记·算法
七号驿栈41 分钟前
深入理解 MAC 消息认证算法:原理、分类与应用
算法
bnmoel44 分钟前
数据结构深度剖析二叉树・下篇:链式结构的实现 ,遍历方法全解析
c语言·数据结构·算法·二叉树·
男孩李1 小时前
浅谈Linux的last命令
java·linux·服务器
豆瓣鸡1 小时前
算法日记 - Day5
java·算法
掉鱼的猫1 小时前
Solon 的 10 种 HTTP 服务器:改一行依赖,换一个引擎
java·serverless
Accerlator1 小时前
RAG 评测
算法