【算法练习】数据结构/树

王道机试对应章节

牛客网的题

poj的题

面试精心list中常问到的

最近公共祖先

//求二叉树某结点的最近公共父结点
#include<cstdio>
#include <string.h>
long long com(long long a,long long b){
    if(a==b) return a;
    else if(a>b) return com(a/2,b);
    else return com(a,b/2);
}
int main(){
    long long a,b;
    while(scanf("%lld%lld",&a,&b)!=EOF){
        printf("%lld\n",com(a,b));
    }
    return 0;
}

//
// Created by syx on 2019/6/7.
//

特殊题目 

和一般求法

猜你喜欢

转载自blog.csdn.net/weixin_40760678/article/details/100085882