力扣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;
}
相关推荐
Jelena157795857922 小时前
电商运营分析数据比价接口实战:多平台价格监控与智能决策系统
java·大数据·数据库
神明不懂浪漫3 小时前
【第五章】Java中的继承与多态
java·开发语言
AI多Agent协作实战派5 小时前
AI多Agent协作系统实战(十七):凌晨4点,我的AI系统在“假装工作“——3个bug同时爆炸的5小时
java·前端·bug
gaolei_eit5 小时前
Java+Ai+vue
java·spring·maven
qq_2518364575 小时前
基于java Web 动漫视频网站毕业论文
java·开发语言·前端
LayZhangStrive5 小时前
JUC相关的函数、注解、变量杂记
java·面试·多线程·juc
未秃头的程序猿5 小时前
给公司做了个AI客服Agent,用的Spring AI 1.0,3天上线领导拍板了
java·后端·ai编程
来一碗刘肉面5 小时前
栈的应用(表达式求值)
数据结构·算法
曹牧5 小时前
Eclipse 批量文本替换
java·ide·eclipse