文章

11

粉丝

27

获赞

19

访问

1.2k

头像
判断二叉树是否对称 题解:无需建树
P1551 东北大学机试题
发布于2025年1月11日 19:22
阅读数 171

思路:将每一层结点单独保存在string b 中,再依次判断b是否对称

#include<bits/stdc++.h>
using namespace std;

//1551-判断二叉树是否镜像对称 
bool isduichen(string &b,int n){            //没加&前b[i]没有值 
    int i,j=n-1;
    for(i=0;i<j;i++,j--){
        if((b[j]=='#' && b[i]!='#')||(b[j]!='#' && b[i]=='#')) return false;
    }
    return true;
}


int main(){
    string a,b;
    while(cin>>a){
        int n=a.length();
        int h=ceil(log(n)/log(2));
        int k=0; 
        bool flag=true;
        for(int i=1;i<h;i++){
            k=0;
       &...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发