力扣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;
}
相关推荐
JAVA面经实录91714 小时前
Java开发工程基础完整手册(企业实战完整版)
java·开发语言·git·ci/cd·svn·github·intellij idea
李艺为14 小时前
Fake Device Test作假屏幕分辨率分析
android·java
样例过了就是过了14 小时前
LeetCode热题100 最长有效括号
c++·算法·leetcode·动态规划
无敌的黑星星14 小时前
Spring @Transactional 注解全解析
java·数据库·oracle
xiaogg367814 小时前
spring oauth2 单点登录
java·vue.js·spring
wayz1114 小时前
Day 18:Keras深度学习框架入门
人工智能·深度学习·神经网络·算法·机器学习·keras
一行代码一行诗++14 小时前
C语言中if的使用
c语言·c++·算法
AI科技星14 小时前
《基于 1 的 N 维分形与对称统一理论》
人工智能·算法·机器学习·数学建模·数据挖掘
c++之路14 小时前
C++ STL
java·开发语言·c++
wljy114 小时前
牛客每日一题(2026.4.30) 整数域二分
c语言·c++·算法·蓝桥杯·二分