力扣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;
}
相关推荐
皮皮林5512 小时前
拒绝写重复代码,试试这套开源的 SpringBoot 组件,效率翻倍~
java·spring boot
归去_来兮3 小时前
拉格朗日插值算法原理及简单示例
算法·数据分析·拉格朗日插值
顺风尿一寸5 小时前
从 Java NIO poll 到 Linux 内核 poll:一次系统调用的完整旅程
java
程途知微5 小时前
JVM运行时数据区各区域作用与溢出原理
java
华仔啊8 小时前
为啥不用 MP 的 saveOrUpdateBatch?MySQL 一条 SQL 批量增改才是最优解
java·后端
千寻girling10 小时前
Python 是用来做 AI 人工智能 的 , 不适合开发 Web 网站 | 《Web框架》
人工智能·后端·算法
xiaoye201810 小时前
Lettuce连接模型、命令执行、Pipeline 浅析
java
颜酱13 小时前
一步步实现字符串计算器:从「转整数」到「带括号与优化」
javascript·后端·算法
beata13 小时前
Java基础-18:Java开发中的常用设计模式:深入解析与实战应用
java·后端
Seven9714 小时前
剑指offer-81、⼆叉搜索树的最近公共祖先
java