力扣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;
}
相关推荐
Java面试题总结7 小时前
FVG3 构建系统 MinGW 配置问题排查文档
java
乐之者v7 小时前
游标分批查询,提高查询性能
java
CM莫问7 小时前
详解机器学习中的马尔可夫链
人工智能·算法·机器学习·概率论·马尔可夫·马尔科夫
南宫萧幕7 小时前
基于 Luenberger 观测器的 PMSM 无速度传感器 id=0 矢量控制系统 Simulink 建模与实现(一)
算法·matlab·汽车·控制
城管不管7 小时前
嵌入模型Embedding Model
java·开发语言·python·embedding·嵌入模型
斯维赤7 小时前
每天学习一个小算法:选择排序
java·学习·算法
超级码力6667 小时前
【Latex第三方文档类standalone】standalone类介绍及应用
算法·数学建模·信息可视化
明朝百晓生7 小时前
强化学习 [chapter10] [page3 ]Actor-Critic Methods
算法
book123_0_997 小时前
Spring Boot 条件注解:@ConditionalOnProperty 完全解析
java·spring boot·后端
NCIN EXPE8 小时前
使用Springboot + netty 打造聊天服务(一)
java·spring boot·后端