力扣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;
}
相关推荐
Yfhonier15 分钟前
6440. 极大连通图个数(DFS)
数据结构·算法·深度优先
xieliyu.18 分钟前
计算机网络|数据链路层详解:MAC 地址、交换机、ARP 协议、CRC 校验
java·网络·笔记·计算机网络·java-ee
SimonKing23 分钟前
手机投屏到电脑,不用装任何 App,这个开源工具免费搞定:QtScrcpy
java·后端·程序员
玖玥拾27 分钟前
LeetCode 1 两数之和
算法·leetcode·职场和发展
Cccp.12327 分钟前
【leetcode】(一)认识复杂度和简单排序算法
算法·排序算法
学长毕业设计31 分钟前
基于SpringBoot的奶茶店服务管理系统的设计与实现(源码+文档+讲解视频)
java·spring boot·后端
蛋先生DX35 分钟前
明明都是源码到CPU,各语言中间原理咋不是一个套路?
java·javascript·go
旖旎夜光36 分钟前
LeetCode 974:和可被 K 整除的子数组(前缀和) —— 题解
数据结构·c++·算法·leetcode·前缀和
萧瑟余晖40 分钟前
Java深入解析篇十三之Java日志API(JUL)详解
java·开发语言