力扣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;
}
相关推荐
白鸽(二般)2 小时前
MinIO Java Client API
java·开发语言
普通攻击往后拉2 小时前
Leetcode 206. 反转链表
算法·leetcode·链表
软萌萌的12 小时前
Java Spring Boot 修改yml配置&加载顺序规则
java·spring boot·python
@syh.3 小时前
【贪心】矩阵消除游戏
算法·游戏·矩阵
IT小盘3 小时前
13-企业Prompt模板-角色任务约束与输出格式
java·前端·prompt
爱敲键盘的猴子3 小时前
Java并发编程 -- volatile
java·java并发
可编程芯片开发3 小时前
基于零极点配置的PID控制系统simulink建模与仿真
算法
徐小夕4 小时前
开源!我用SQLite + DuckDB打造了一款可视化AI问数平台
前端·算法·github
Hrain-AI4 小时前
2026 企业 AI 智能体平台横评:8 大主流平台 7 维度实测对比
人工智能·算法·机器学习