力扣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;
}
相关推荐
Navigator_Z35 分钟前
LeetCode //C - 1293. Shortest Path in a Grid with Obstacles Elimination
c语言·算法·leetcode
小蒜学长1 小时前
微信小程序-高校自习室管理系统(代码+数据库+LW)
java·spring boot·后端·微信小程序·自习室管理
Nil2081 小时前
leetcode 64最小路径和
算法·leetcode·职场和发展
光影少年1 小时前
AI Agent、自动化与未来工作
人工智能·算法·架构
鸥梨菌Honevid1 小时前
UVM 中 REQ 和 RSP 类型详解:从通信模型到 item_done 与 put_response
java·前端·servlet
瑞克-桑切斯1 小时前
真实企业场景 运维安全与管理
java·网络·github
牧羊人.3331 小时前
计算机视觉基础 第16章|EigenFace,FisherFace,LBPH传统人脸识别算法
人工智能·算法·计算机视觉
Nil2082 小时前
leetcode 72编辑距离
算法·leetcode·职场和发展
老板一杯拿铁2 小时前
Java 八股文面试详解:从基础到进阶的全面梳理
java·面试
const_qiu2 小时前
第 2.5 章 2.5.4-2.5.5:JWT 双 Token 与声明式权限守卫
java·人工智能