首页 > 其他 > 详细

leetcode1104

时间:2019-06-30 13:35:51      阅读:105      评论:0      收藏:0      [点我收藏+]
 1 import math
 2 class Solution:
 3     def findParent(self,label,pardepth):
 4         psum = 2**(pardepth-1) + 2**(pardepth) - 1
 5         label = label // 2
 6         dlabel = psum - label
 7         return dlabel 
 8 
 9     def pathInZigZagTree(self, label: int) -> List[int]:
10         depth = math.ceil(math.log(label,2))
11         if label == 2 ** depth:
12             depth += 1
13         #print(depth)
14         res = [label]
15         while depth > 1:
16             label = self.findParent(label,depth-1)
17             res.insert(0,label)
18             depth -= 1 
19         return res

 

leetcode1104

原文:https://www.cnblogs.com/asenyang/p/11109426.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!