题解 | 二叉树

二叉树

https://www.nowcoder.com/practice/5b80ab166efa4551844657603227caeb

#include<iostream>
using namespace std;
int common_father(int x,int y){
    if(x==y){
        return x;
    }
    else if(x>y){
        return common_father(x/2,y);
    }
    else{
        return common_father(x,y/2);
    }
}
int main(){
    int x,y;
    while(cin>>x>>y){
        cout<<common_father(x,y)<<endl;
    }
}

全部评论

相关推荐

07-02 13:50
闽江学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务