题解 | 二叉树

二叉树

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

from collections import defaultdict,deque

def same_father(a:int,b:int):
    temp1=a
    temp2=b
    while temp1!=temp2:
        while temp1>temp2 :
            if temp1%2==1:
                temp1=(temp1-1)//2
            else:
                temp1=temp1//2
        while temp2 > temp1 :
                if temp2%2==1:
                    temp2=(temp2-1)//2
                else:
                    temp2=temp2//2
    if temp1>1:
        return temp1
    else:
        return 1


if __name__=="__main__":
    while True:
        try:
            string=input().split()
            a,b=int(string[0]),int(string[1])
            
            print(same_father(a,b))
        except EOFError:
            break

全部评论

相关推荐

野猪不是猪🐗:我assume that你must技术aspect是solid的,temperament也挺good的,however面试不太serious,generally会feel style上不够sharp
点赞 评论 收藏
分享
lllllkin:感觉可以精简到一页简历,有些排版感觉不是必须的。 时间线越早的,你自己越熟悉的放前面。描述可以更精简些,一些问题解决感觉可以不用写具体技术栈,卖个关子,等面试官问。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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