力扣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;
}
相关推荐
金銀銅鐵6 小时前
为什么枚举类中可以定义抽象方法
java·后端·ai编程
文丑颜不良啊7 小时前
LeetCode1941~1960题目解析
java·leetcode
txxzjmzlh7 小时前
SpringBoot 统⼀功能处理
java·spring boot·后端
nice_lcj5209 小时前
Java Lambda 表达式入门:怎么写、怎么用、常用方法有哪些
java·开发语言·后端·面试
码农小河6610 小时前
基于SSM+JSP+MySQL的在线医疗服务系统的设计与实现
java·开发语言·mysql
老师我太想进步了202610 小时前
【数据结构-4】算法美学之顺序表
数据结构·算法
风影同志7832411 小时前
编码器是激活函数吗?—— 一个看起来很像、其实不是的类比
算法
SL_staff11 小时前
从配置失效到逻辑复用:JVS-Logic 如何构建可治理的业务编排中枢
java·spring·产品
特立独行的猫A11 小时前
一份 Markdown 发十个平台:cspub 一稿多投
java·后端·python
UIU11411 小时前
P1481 魔族密码
c++·算法·动态规划