力扣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;
}
相关推荐
极光代码工作室3 小时前
基于SpringBoot的课程预约系统
java·springboot·web开发·后端开发
圣保罗的大教堂3 小时前
leetcode 3517. 最小回文排列 I 中等
leetcode
土豆.exe3 小时前
Fastjson2 2.0.53 哈希碰撞 RCE:从原理到三种打法
算法·哈希算法
Leighteen3 小时前
`try-finally` 里的 `return`:为什么 `finally` 会悄悄改掉返回值、吞掉异常
java·开发语言
黄河123长江3 小时前
有限Abel群的结构()
算法
名字还没想好☜4 小时前
Go 的 time.After 在 select 循环里内存泄漏:定时器堆积原理与 timer.Reset 正确姿势
java·数据库·golang·go·goroutine
Jerry4 小时前
LeetCode 92. 反转链表 II
算法
骊城英雄4 小时前
Rust从入门到精通-trait
人工智能·算法·rust
圆山猫4 小时前
[Virtualization](三):RISC-V H-extension 与 Guest 执行模式
android·java·risc-v
caishenzhibiao4 小时前
期货先行者主图 同花顺期货通指标
java·c语言·c#