力扣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;
}
相关推荐
峰回路转之后几秒前
SmartBi集成到第三方系统
java
gorgeous(๑>؂<๑)2 分钟前
【ICLR26-Oral Paper-Meta】先见之明:揭秘语言预训练中大型语言模型的视觉先验
人工智能·深度学习·算法·机器学习·语言模型
一条咸鱼_SaltyFish3 分钟前
大文件性能优化:从百倍提升看底层原理的实践思考
java·性能优化·架构演进·大文件处理·nagle·零对象设计
好家伙VCC5 分钟前
**发散创新:用 Rust构建多智能体系统,让分布式协作更高效**在人工智能快速演进的今天,**多智能体系统(
java·人工智能·分布式·python·rust
tod1136 分钟前
力扣基础算法分类刷题:位运算、数学、数组与字符串详解
算法·leetcode·职场和发展
ValhallaCoder6 分钟前
hot100-图论
数据结构·python·算法·图论
小沈同学呀6 分钟前
Spring Boot实现加密字段模糊查询的最佳实践
java·spring boot·后端·encrypt
万能的小裴同学8 分钟前
饥荒Mod
java·开发语言·junit
熬了夜的程序员9 分钟前
【LeetCode】118. 杨辉三角
linux·算法·leetcode
智算菩萨11 分钟前
规模定律的边际递减与后训练时代的理论重构
人工智能·算法