力扣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;
}
相关推荐
Resean02239 小时前
架构设计系列(十六):DDD 与代码架构
java·开发语言·架构
学长毕设9 小时前
基于SpringBoot 车辆租赁系统平台-附源码
java·spring boot·后端
Flynt11 小时前
Spring AI Alibaba 真停更了?我把它的 GitHub 翻了个底朝天
java·spring·开源
民乐团扒谱机14 小时前
【超详细】基频音高提取算法之SWIPE 算法深度解析:频谱匹配的精度极限与工程边界
人工智能·算法
饮水桶_T14 小时前
C++ stack & queue复习笔记
开发语言·笔记·算法
她的男孩14 小时前
Spring Boot 接 Flowable:请假单要同时走财务和行政,包容分支和默认分支怎么配
java·spring boot·工作流引擎
wy_hhxx15 小时前
[Leetcode] 滑动窗口
算法·leetcode·滑动窗口
咖啡八杯15 小时前
LoginUser 适配器模式:适配 SysUser 到 UserDetails
java·开发语言·后端·框架·适配器模式·若依
码途行者16 小时前
每天10分钟学Go:第20课 泛型
c++·算法·golang