力扣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;
}
相关推荐
君义_noip2 小时前
信息学奥赛一本通 1661:有趣的数列 | 洛谷 P3200 [HNOI2009] 有趣的数列
c++·算法·组合数学·信息学奥赛·csp-s
程序员:钧念2 小时前
深度学习与强化学习的区别
人工智能·python·深度学习·算法·transformer·rag
英英_3 小时前
MATLAB数值计算基础教程
数据结构·算法·matlab
一起养小猫3 小时前
LeetCode100天Day14-轮转数组与买卖股票最佳时机
算法·leetcode·职场和发展
hele_two4 小时前
快速幂算法
c++·python·算法
kk哥88994 小时前
如何快速掌握JavaSE的核心语法?
java
我是一只小青蛙8884 小时前
AVL树:平衡二叉搜索树原理与C++实战
java·jvm·面试
浩瀚地学4 小时前
【Java】JDK8的一些新特性
java·开发语言·经验分享·笔记·学习
l1t4 小时前
利用DeepSeek将python DLX求解数独程序格式化并改成3.x版本
开发语言·python·算法·数独