力扣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;
}
相关推荐
吞下星星的少年·-·11 分钟前
Div.2 CF 1130B题(构造,贪心)
算法·贪心·构造
文丑颜不良啊14 分钟前
LeetCode1481~1500题目解析
java·leetcode
2601_9628857215 分钟前
quotes 字段全解:涨跌幅、振幅、换手率的口径与单位
java·前端·spring
前端精髓40 分钟前
调用openrouter的免费API模型
java·前端·javascript
步行cgn1 小时前
Spring MVC 拦截器 Interceptor 详解:从执行流程到实战应用
java·spring·mvc
文丑颜不良啊1 小时前
LeetCode1381~1400题目解析
java·leetcode
开开心心_Every1 小时前
快速隐藏程序工具自定义快捷键一键切换
java·开发语言·前端·spring·智能手机·word·intellij-idea
是main不是漫1 小时前
【双指针——移动零】数组划分类题目的入门基石
c++·算法
萧瑟余晖2 小时前
Spring Batch核心模型与快速上手详解
java·spring·batch
缓慢更新2 小时前
AI 辅助生成单测:从接口定义到用例的流水线
java·服务器·前端·网络·数据库·人工智能