力扣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;
}
相关推荐
AI科技星14 分钟前
基于32维Cayley_Dickson超复数的全域拓扑统一场论——反重力、真空自持供能、维度瞬移与星际宇宙脑秩序体系
人工智能·学习·算法·机器学习·数据挖掘
我是个假程序员16 分钟前
实例化动作脚本类,并执行,执行类似N_F1_SAVE.java这种
java·nc
aichitang202421 分钟前
数论变换(NTT)
c++·算法·fft·ntt
_olone24 分钟前
AtCoder Beginner Contest 465 D - X to Y
c++·算法
青山木28 分钟前
Hot 100 --- LRU 缓存
java·数据结构·算法·leetcode·链表·缓存·哈希
“码”力全开29 分钟前
ONVIF摄像头接入项目实战记录
人工智能·算法·边缘计算
花生了什么事o30 分钟前
Java 线程池:从参数到拒绝策略
java·jvm
长孙豪翔40 分钟前
引发事件的问题
java·linux·数据库
happyprince42 分钟前
09-vLLM KV Cache 系统完整分析
java·spring·vllm
掉鱼的猫43 分钟前
ReActAgent 使用指南:构建会思考、能行动的 AI Agent
java·llm·agent