力扣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;
}
相关推荐
阿里云云原生1 分钟前
告别“看不见的内存”!SysOM 如何实现 Java 进程内存全景分析?
java·云原生
Andy工程师7 分钟前
Spring Boot 按照以下顺序加载配置(后面的会覆盖前面的):
java·spring boot·后端
繁星蓝雨7 分钟前
小试Spring boot项目程序(进行get、post方法、打包运行)——————附带详细代码与示例
java·spring boot·后端
加藤不太惠8 分钟前
【无标题】
java·数据结构·算法
金色旭光11 分钟前
目标追踪算法+卡尔曼滤波原理+ByteTrack使用
算法
Knight_AL20 分钟前
如何在 Spring Boot 中集成 IP2Region 实现高效 IP 地址地理位置查询
java·spring boot·tcp/ip
山枕檀痕28 分钟前
Spring Boot中LocalDateTime接收“yyyy-MM-dd HH:mm:ss“格式参数的最佳实践
java·spring boot·后端
乔伊酱32 分钟前
Bean Searcher 遇“鬼”记:为何我的查询条件偷偷跑进了 HAVING?
java·前端·orm
invicinble32 分钟前
idea提供maven处理机制
java·maven·intellij-idea