力扣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;
}
相关推荐
郑州光合科技余经理8 分钟前
同城商城源码:商品库和订单库怎么随包交付
android·java·开发语言·后端·uni-app·php·ai编程
\光辉岁月/9 分钟前
4.String类
java·面向对象·stringbuilder·string·stringbuffer·字符串类
蚰蜒螟30 分钟前
从 Java SocketChannel 到 TCP 挥手:一次 close() 的完整调用链与引用计数解析
java·python·tcp/ip
damoluomu33 分钟前
国产 Java CMS 的协议和坑,讲清楚
java·开发语言
Wang's Blog41 分钟前
Java 项目实战: 交友项目 - 黑名单:分页查询黑名单
java·开发语言·交友
蚰蜒螟1 小时前
从 Java write 到磁盘扇区:一次写入操作的完整内核穿越之旅
java·开发语言
u0111026751 小时前
图片生成任务的日志记录与敏感信息取舍
前端·图像处理·算法·ai作画
en.en..1 小时前
volatile 关键字整理(嵌入式 C 标准)
java·开发语言
captain3761 小时前
Spring IoC和DI(2)
java·后端·spring