力扣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;
}
相关推荐
2401_872418782 小时前
算法入门:数据结构-堆
数据结构·算法
石山代码3 小时前
ArrayList / HashMap / ConcurrentHashMap
java·开发语言
xwz小王子3 小时前
手术机器人登上Science Robotics:2毫米纤细手臂,从3厘米切口完成腰椎神经减压
算法·机器人
AskHarries4 小时前
系统提示词、开发者指令和用户输入的优先级
java·前端·数据库
黎阳之光4 小时前
视频孪生智护供水生命线:黎阳之光赋能医疗与园区水务高质量升级
运维·物联网·算法·安全·数字孪生
daidaidaiyu5 小时前
ThingsBoard 规则链系统源码分析和自定义定时器
java
Black蜡笔小新5 小时前
自动化AI算法训练服务器DLTM制造业AI质检工作站助力制造业实现AI智检
人工智能·算法·自动化
嵌入式小能手5 小时前
飞凌嵌入式ElfBoard-进程间的通信之命名管道
linux·服务器·算法
小毛驴8505 小时前
spring-boot-maven-plugin,maven-compiler-plugin 功能对比
java·python·maven
啦哈拉哈5 小时前
Leetcode题解记录-hot100(81-100)
算法·leetcode·职场和发展