主站
DreamJudge
院校信息
专业题库
模拟考试
机试真题
专业课程
讨论区
兑换中心
登录
注册
发布
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
今夕何夕12211
2024年3月27日 10:44
判断二叉树是否对称 题解:
P1551
回复 1
|
赞 0
|
浏览 226
求助 显示超时 准确率只有77% #include <stdio.h> #include <string.h> #include <math.h> int check(char a[],int x,int y) { int i=x; int j=y; while(i<j) { if(a[i]==a[j]) &nbs...
孙某人
2024年2月29日 12:00
判断二叉树是否对称 题解:新手方法 易于理解
P1551
回复 1
|
赞 2
|
浏览 523
#include <iostream> #include<string.h> #include <math.h> using namespace std; int main(){ char a[1005]; for(int i=0;i<1005;i++) a[i]=0; gets(a); int len=strlen(a); int high=0; for(int i=1;;i++){ if((len+1)<=pow(2.0,i)) { high=i; break; ...
小王桐学
2024年2月24日 16:26
判断二叉树是否对称 题解:C
P1551
回复 0
|
赞 0
|
浏览 452
第一层(2^0)1个,第二层(2^1)2个,第三层(2^2)4个。。。。。。。。 #include <stdio.h> #include <string.h> #include <math.h> int JudgeSymmetry(char *t,int n) { int i = 0,j,k,m,l = 0; while(i < n) { j = pow(2,l); k = i; m = k+j-1; while(k <= m && m < n) { ...
xx_about123456
2022年8月7日 10:32
只区分空节点与非空结点 解决对称问题
P1551
回复 0
|
赞 2
|
浏览 4.7k
思路: 将非空结点的值修改成相同的值(如t),这样树的结点要么为#,要么为t; 逐层判断(1----2----4-----8)每层的字符数按照这样的规律提取子串,子串倒转之后,内容不变,即对称; 带注释代码 #include <bits/stdc++.h> using namespace std; int main() { string str; cin>>str; int flag=0; int len = str.length(); for(int i=0;...
zjx140
2022年1月6日 19:29
层级遍历方式,每层进行对称性判断
P1551
回复 0
|
赞 0
|
浏览 6.8k
#include<iostream> #include<queue> using namespace std; int main(){ string s; queue<int> que; //编号队列 cin >> s; bool result = true; if(s[0]!= '#') que.push(0); while(!que.empty()){ int size = que.size(); string temp; // 接住每层构成的字符串 for(int i = 0;i &...
鱼翔浅底
2021年1月29日 12:29
判断二叉树是否对称
P1551
回复 1
|
赞 1
|
浏览 9.9k
数组存储,一层层往下判断 #include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> //判断 int Judge(char *s,int start,int end,int len) { if (end>=len) { return 1; } for (int i = start,j=end; i<=j; i++,j--) { ...
山楂
2021年2月24日 21:18
把二叉树当成满二叉树处理,每层进行对称判断,不需要构造二叉树
P1551
回复 0
|
赞 1
|
浏览 8.8k
#include<iostream> #include<queue> #include<vector> #include<string> using namespace std; string s; //k , l 为该层起始下标 bool symmetry(int k, int l) { while (k <= l) { if ( (s[k] == '#' && s[l] != '#') ||\ (s[k...
James
2021年2月1日 14:43
先重建树 然后两个方向递归
P1551
回复 0
|
赞 0
|
浏览 8.4k
#include<iostream> #include<queue> #include<string> #include<string.h> using namespace std; typedef struct node{ char data; struct node*lchild; struct node*rchild; }BiNode,*BiTree; queue<BiTree> q; ...
别再熬夜
2021年1月28日 10:57
左右分别往下比较,递归比较
P1551
回复 0
|
赞 0
|
浏览 8.3k
#include <bits/stdc++.h> using namespace std; bool symmetry(string s,int l,int r)//l是左边待判断的结点号,r是右边 { if(l>=s.length())return true; if(r>=s.length()&&s[l]=='#') return true; if(r>=s.length()&&s[l]!='#') return false; if...
老猫
2021年1月19日 16:40
记录
P1551
回复 0
|
赞 0
|
浏览 7.5k
#include <iostream> #include <string> #include <string.h> using namespace std; bool levelsym(string s) { int len=s.size(); int i=0,j=len-1; while(i<=j) { if(s[i]!=s[j]) return false; i++; j--; } return true; } int main() { string level...
1
2
题目
判断二叉树是否对称
题解数量
12
发布题解
热门题解
1
只区分空节点与非空结点 解决对称问题
2
判断二叉树是否对称 题解:新手方法 易于理解
3
把二叉树当成满二叉树处理,每层进行对称判断,不需要构造二叉树
4
判断二叉树是否对称
5
只区分叶子和非叶子,直接reverse进行比较每一层
6
111
7
记录
8
左右分别往下比较,递归比较
9
先重建树 然后两个方向递归
10
层级遍历方式,每层进行对称性判断