力扣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 小时前
带您看懂字节码指令(一):一帧里有什么
java·后端·ai编程
专注仿真3 小时前
知识问答模型用到的算法集详解及代码实例
python·算法·代码·大模型训练·控制算法
nice_lcj5204 小时前
【从零理解 Spring AI · 14】RAG 的四个环节:加载、切分、向量化、检索
java·spring boot·embedding·向量数据库·rag·spring ai·ai应用开发
罗西的思考4 小时前
【轻量化复刻大模型 / KIMI K3】AttnRes 模块交互式演示
人工智能·算法·机器学习
学长毕设5 小时前
基于springboot科创竞赛信息平台-附源码
java·spring boot·后端
聪明的笨猪猪6 小时前
Java 工程案例:AI 生成 @Async 异步线程池踩坑
java·经验分享·面试·ai编程
学长毕设6 小时前
基于SpringBoot公务员考试交流平台-附源码
java·spring boot·后端
好悬给我拽开线8 小时前
ZILOT 论文解析
算法
SL_staff9 小时前
私有化低代码:面向强监管行业的可控数字化实践
java·低代码
饮水桶_T9 小时前
JAVA IO流笔记
开发语言·数据结构·算法