力扣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;
}
相关推荐
Wect6 小时前
LeetCode 39. 组合总和:DFS回溯解法详解
前端·算法·typescript
Wect6 小时前
LeetCode 46. 全排列:深度解析+代码拆解
前端·算法·typescript
颜酱6 小时前
Dijkstra 算法:从 BFS 到带权最短路径
javascript·后端·算法
用户8307196840827 小时前
Spring Boot WebClient性能比RestTemplate高?看完秒懂!
java·spring boot
木心月转码ing9 小时前
Hot100-Day24-T128最长连续序列
算法
Assby9 小时前
从洋葱模型看Java与Go的设计哲学:为什么它们如此不同?
java·后端·架构
小肥柴9 小时前
A2UI:面向 Agent 的声明式 UI 协议(三):相关概念和技术架构
算法
belhomme10 小时前
(面试题)Netty 线程模型
java·面试·netty
学高数就犯困11 小时前
性能优化:LRU缓存(清晰易懂带图解)
算法