1 Star 0 Fork 0

MetaverseMobile/leetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
965_单值二叉树.cpp 1.01 KB
一键复制 编辑 原始数据 按行查看 历史
TieNan2019 提交于 2020-10-28 13:54 +08:00 . Create 965_单值二叉树.cpp
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool isUnivalTree(TreeNode* root) {
bool cur = true;
if (root->left == NULL && root->right == NULL)
return true;
else if (root->left == NULL)
return (root->val == root->right->val) && isUnivalTree(root->right);
else if (root->right == NULL)
return (root->val == root->left->val) && isUnivalTree(root->left);
else
return (root->val == root->left->val) && isUnivalTree(root->left)
&& (root->val == root->right->val) && isUnivalTree(root->right);
// cout << root->val << " : " << root->left->val << " " << root->right->val;
return true;
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/MetaverseMobile/leetcode.git
git@gitee.com:MetaverseMobile/leetcode.git
MetaverseMobile
leetcode
leetcode
main

搜索帮助

371d5123 14472233 46e8bd33 14472233