力扣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;
}
相关推荐
:-)29 分钟前
基础算法-选择排序
数据结构·算法·排序算法
浮沉98735 分钟前
二分查找算法例题(一)
算法
C+-C资深大佬36 分钟前
Java 变量:从入门到精通
java·开发语言·python
Flittly1 小时前
【日常小问】Docker 部署 Nacos 2.4.3,Dubbo 3.3 连接 Config Service 失败排查
java·spring boot·dubbo
退休倒计时1 小时前
【每日一题】LeetCode 17. 电话号码的字母组合 TypeScript
算法·leetcode·typescript
粘稠的浆糊1 小时前
[AtCoder - abc465_d ]X to Y题解
数据结构·c++·算法
鱼儿也有烦恼1 小时前
数据结构合集
算法·algorithm
kuonyuma1 小时前
java之动态代理
java·开发语言
衔烛之龙11 小时前
Windows x64 构建 liboqs-java教程
java·windows·python
一路向北North1 小时前
Spring Security OAuth2.0(20):完善环境配置
java·后端·spring