力扣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;
}
相关推荐
小坏讲微服务24 分钟前
SpringBoot4.0整合knife4j 在线文档完整使用
java·spring cloud·在线文档·knife4j·文档·接口文档·swagger-ui
8***Z8933 分钟前
springboot 异步操作
java·spring boot·mybatis
i***132438 分钟前
Spring BOOT 启动参数
java·spring boot·后端
坚持不懈的大白40 分钟前
后端:SpringMVC
java
IT_Octopus41 分钟前
(旧)Spring Securit 实现JWT token认证(多平台登录&部分鉴权)
java·后端·spring
kk哥88991 小时前
Spring详解
java·后端·spring
S***26751 小时前
Spring Cloud Gateway 整合Spring Security
java·后端·spring
Tao____1 小时前
开源物联网平台
java·物联网·mqtt·开源·设备对接
遇到困难睡大觉哈哈1 小时前
Harmony os——ArkTS 语言笔记(四):类、对象、接口和抽象类
java·笔记·spring·harmonyos·鸿蒙
拿破轮2 小时前
使用通义灵码解决复杂正则表达式替换字符串的问题.
java·服务器·前端