当前位置:网站首页>[force buckle] single valued binary tree
[force buckle] single valued binary tree
2022-07-19 06:26:00 【Patrick star`】
965. Single valued binary trees - Power button (LeetCode)
subject :
If each node of the binary tree has the same value , Then the binary tree is Single value Binary tree .
Only when the given tree is a single valued binary tree , To return to true; Otherwise return to false.
Ideas :
If it is empty, return true
If root Left of / When the right child is not empty , Compare left / Right child and root The value of the node , Unequal return false
Code :
bool isUnivalTree(struct TreeNode* root){
if(root == NULL)
{
return true;
}
if(root->left)
{
if(root->left->val != root->val)
{
return false;
}
}
if(root->right)
{
if(root->right->val != root->val)
{
return false;
}
}
bool ret1 = isUnivalTree(root->left);
bool ret2 = isUnivalTree(root->right);
return ret1&&ret2;
}边栏推荐
猜你喜欢

Talking about several solutions of cross domain

【力扣】环形链表 II

2021 - 09 - 15

Unity2D学习 Fox Game制作 过程1:基本的游戏角色控制,动画效果,镜头控制,物品收集,bug优化

你的企业最适合哪种深度学习?
![Vscode instant English translation plug-in [translation (English Chinese Dictionary)]](/img/f4/9bd90910fef061b423ea8309fab439.png)
Vscode instant English translation plug-in [translation (English Chinese Dictionary)]

【力扣】对称二叉树

2022/07/12 学习笔记 (day05)循环

[antdv: Each record in table should have a unique `key` prop,or set `rowKey` to an unique.....

RestClient-多条件聚合
随机推荐
虚拟现实中的眼睛跟踪
Typescript learning
Qt Creator闪退解决办法
busybox 指定日期修改 暂时不需要clock -w 写入硬件
Interview review nth time
mapping索引属性 & 创建索的操作
Creation and implementation of WebService interface
Acwing game 57 (AK)
[simple and fast] after startup, the desktop is normal, and the taskbar below is unresponsive / the mouse keeps turning
In Chapter 5, can we directly call the run () method to start a new thread
Configure the 'log' shortcut key in vscode and remove the console log(‘‘); Semicolon in;
RestClient查询文档
Qtss callback routine
2022/07/09 第五小组 丁帅 学习笔记 day02
计算几何(2)
Introduction to basic knowledge of Minio
數學基礎課2_歐拉函數,線性篩,擴歐
Quantum three body problem: an overview of numerical computation
Vscode instant English translation plug-in [translation (English Chinese Dictionary)]
XOR-gun (位运算,思维,区间暴力)