力扣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;
}
相关推荐
是梦终空几秒前
计算机毕业设计252—基于Java+Springboot+vue3+协同过滤推荐算法的农产品销售系统(源代码+数据库+2万字论文)
java·spring boot·vue·毕业设计·源代码·协同过滤算法·农产品销售系统
2301_764441336 分钟前
使用python构建的应急物资代储博弈模型
开发语言·python·算法
丿BAIKAL巛8 分钟前
Java前后端传参与接收全解析
java·开发语言
cc蒲公英26 分钟前
javascript有哪些内置对象
java·前端·javascript
guslegend28 分钟前
Spring AOP高级应用与源码剖析
java
Rover.x28 分钟前
head table is mandatory
java·apache
yanghuashuiyue29 分钟前
Java过滤器-拦截器-AOP-Controller
java·开发语言
shoubepatien30 分钟前
JAVA —— 03
java·jvm
a努力。32 分钟前
【基础数据篇】数据等价裁判:Comparer模式
java·后端
hetao173383732 分钟前
2025-12-11 hetao1733837的刷题笔记
c++·笔记·算法