力扣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;
}
相关推荐
动词ing16 分钟前
【C语言】自定义函数+指针入门
c语言·开发语言·算法
重生之后端学习30 分钟前
283. 移动零[简单]✅
开发语言·数据结构·算法·leetcode·职场和发展
吠品44 分钟前
Wine 在 Linux 上运行 Windows 软件完整指南
java·linux·服务器
一只小小的芙厨1 小时前
基础数论总结
笔记·学习·算法
亚历克斯神2 小时前
智能搜索系统的升级复盘——从 Elasticsearch 到混合检索的检索质量提升
java·spring·微服务
夜不会漫长2 小时前
C++入门(1)
开发语言·c++·算法
金銀銅鐵3 小时前
[Java] 一个方法最多可以有多少个入参?
java·jvm
哭哭啼3 小时前
JAVA服务问题诊断
java·开发语言·jvm
wen_zhufeng3 小时前
IndexTTS 2.5 技术报告
人工智能·算法·机器学习
Sayuanni%33 小时前
SpringBoot 从注解到源码:核心知识点总结
java·spring boot·后端