当前位置:网站首页>[force buckle] symmetric binary tree
[force buckle] symmetric binary tree
2022-07-19 06:26:00 【Patrick star`】
101. Symmetric binary tree - Power button (LeetCode)
subject :
Give you the root node of a binary tree root , Check whether it is axisymmetric .

Ideas :
Do not look at the root node , Think of a tree as two trees , If it's a symmetric binary tree , The left child of one tree is equal to the right child of another tree
Code :
bool isSymTree(struct TreeNode* p, struct TreeNode* q){
if(p==NULL && q==NULL)
{
return true;
}
if(q==NULL || p == NULL)
{
return false;
}
if(p->val != q->val)
{
return false;
}
bool ret1 = isSymTree(p->left,q->right);// Compare p The left subtree of q The right subtree
bool ret2 = isSymTree(p->right,q->left);// Compare p Right subtree and q The left subtree
return ret1 && ret2;
}
bool isSymmetric(struct TreeNode* root){
if(root == NULL)
{
return true;
}
return isSymTree(root->left,root->right);// Compare left and right subtrees
}边栏推荐
猜你喜欢
随机推荐
Qtss data type
busybox date 日期增加一天明天 网上都是减一天 昨天
Computational geometry (2)
绝世好题(位运算优化dp)
Busybox date date increases by one day, and decreases by one day on the Internet tomorrow
有依赖的背包,狭义(二进制枚举),广义(树形dp)
MEX and Increments
Learning video saliency from human gaze using candidate selection
[detailed tutorial installation] [configuration] auxiliary plug-ins about eslint in vscode
Cours de mathématiques de base 2 Fonction Euler, écran linéaire, élargissement de l'Europe
WebService接口的创建与实现
Introduction to Darwin streaming server
Lithium battery charging management chip
[simple and fast] after startup, the desktop is normal, and the taskbar below is unresponsive / the mouse keeps turning
Chrome browser settings [display the translation language icon in the upper right corner]
Acwing第57场周赛(AK)
【力扣】二叉树的前序遍历
【力扣】设计循环队列
使用候选选择从人类注视中学习视频显著性
【力扣】括号匹配







