力扣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;
}
相关推荐
zc.z4 小时前
JAVA实现:纯PCM格式音频转换成BASE64
java·音视频·pcm
放羊郎4 小时前
基于ORB-SLAM2算法的优化工作
人工智能·算法·计算机视觉
mask哥4 小时前
力扣算法java实现汇总整理(上)
java·算法·leetcode
如果'\'真能转义说5 小时前
OOXML 文档格式剖析:哈希、ZIP结构与识别
xml·算法·c#·哈希算法
Aaswk5 小时前
Java Lambda 表达式与流处理
java·开发语言·python
是宇写的啊5 小时前
Spring AOP
java·spring
万邦科技Lafite5 小时前
京东item_get接口实战案例:实时商品价格监控全流程解析
java·开发语言·数据库·python·开放api·淘宝开放平台
梦梦代码精6 小时前
BuildingAI 上部署自定义工作流智能体:5 个实用技巧
大数据·人工智能·算法·开源软件
Mr_pyx7 小时前
Spring AI 入门教程:Java开发者的AI应用捷径
java·人工智能·spring