力扣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;
}
相关推荐
mqiqe4 分钟前
AgentScope Java 2.0 Agent 状态存储(AgentStateStore)深度解析:构建可恢复、可扩展的智能体运行时
java·运维·网络
.格子衫.13 分钟前
032动态规划之区间DP——算法备赛
算法·动态规划
zhifou12345616 分钟前
java 17升级安装
java·开发语言
用户37215742613516 分钟前
如何使用 Java 将 Markdown 转换为 PDF(含自定义设置)
java
青 春 记 忆17 分钟前
LeetCode 142. 环形链表 II|Python 解法详解
python·leetcode·链表
不会代码的小猴1 小时前
7. JSON
开发语言·c++·笔记·qt·算法·json
用户3721574261351 小时前
如何使用 Java 在 Word 文档中添加和删除水印:分步指南
java
怪奇云呼军1 小时前
知识库也会注入指令?闪电智能VoiceAgent 如何防住 Prompt Injection
人工智能·python·算法·云计算·音视频
王中阳Go2 小时前
老板用AI三天写到90%,让我明天上线:Java 团队怎么接这10%的烂摊子?
java
阿里云大数据AI技术2 小时前
基于 EMR Serverless Ray 实现 Qwen 模型批量推理实践
人工智能·算法·agent