力扣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;
}
相关推荐
高斯林.神犇12 分钟前
idea快捷键
java·ide·intellij-idea
victory043114 分钟前
PPO GAE优势函数演化和推导
算法
Jasmine_llq22 分钟前
《P3572 [POI 2014] PTA-Little Bird》
算法·滑动窗口·单调队列·动态规划(dp)·多组查询处理·循环优化(宏定义 rep)
tankeven25 分钟前
HJ101 排序
c++·算法
流云鹤26 分钟前
动态规划02
算法·动态规划
青春易逝丶31 分钟前
术语缩写
java
小白菜又菜35 分钟前
Leetcode 236. Lowest Common Ancestor of a Binary Tree
python·算法·leetcode
不想看见40435 分钟前
01 Matrix 基本动态规划:二维--力扣101算法题解笔记
c++·算法·leetcode
ideal-cs38 分钟前
总结:Nginx配置文件案例说明
java·运维·nginx·nginx配置文件
多恩Stone39 分钟前
【3D-AICG 系列-12】Trellis 2 的 Shape VAE 的设计细节 Sparse Residual Autoencoding Layer
人工智能·python·算法·3d·aigc