力扣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;
}
相关推荐
qq_283720051 分钟前
Transformer 高频面试题及答案
算法·面试·transformer
ch.ju2 分钟前
Java程序设计(第3版)第二章——switch case break
java
承渊政道2 分钟前
【递归、搜索与回溯算法】(floodfill算法:从不会做矩阵题,到真正掌握搜索扩散思想)
数据结构·c++·算法·leetcode·矩阵·dfs·bfs
曹牧2 分钟前
Spring MVC中使用HttpServletRequest和HttpServletResponse
java·spring·mvc
谭欣辰4 分钟前
字典树:高效字符串处理利器
c++·算法
我命由我123457 分钟前
Android 开发,getSystemService 警告信息:Must be one of: Context. POWER_SERVICE ...
android·java·java-ee·android studio·android jetpack·android-studio·android runtime
1candobetter8 分钟前
JAVA后端开发—— Maven 生命周期与 IDEA 中Maven 插件面板介绍
java·maven·intellij-idea
Fate_I_C8 分钟前
Kotlin 与 Java 互操作空安全处理策略
java·安全·kotlin
zopple10 分钟前
Laravel3.x经典特性回顾
android·java·数据库
一只小小Java14 分钟前
IDEA 的spring boot yaml没有叶子图标了
java·spring boot·intellij-idea