力扣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;
}
相关推荐
职场的momo6 小时前
11个后端与AI岗位同时开放:Java、网关、推理优化怎么匹配
java·开发语言·人工智能
罗超驿7 小时前
SpringMVC 请求参数接收详解|单个参数、多参数、对象参数、@RequestParam参数重命名
java·后端·postman·javaee
土司大王7 小时前
LeetCode hot100——两两交换链表中的节点
算法·leetcode·职场和发展
古法安卓8 小时前
Android-epoll原理详解
android·java·android studio
大熊背8 小时前
树莓派IspPipeline LSC模块原理详解
算法·lsc·isppipeline·mesh lsc
fireworks998 小时前
接口鉴权(401与403)
java·后端
wear工程师8 小时前
线程池里的异常去哪了?execute 和 submit 不是一回事
java
孔明click338 小时前
别人绕过我的网关直接调用资源服务怎么办?使用 Sa-Token 解决:网关转发鉴权、RPC调用鉴权
java·sa-token·springboot·权限·权限认证
吴声子夜歌8 小时前
Java面试——设计模式(一)
java·设计模式·面试
半亩码田8 小时前
C#转Python第3.6篇:Python 的 @property 比 C# 的 get/set 更灵活
java·python·c#