美文网首页
390. Elimination Game

390. Elimination Game

作者: 阿团相信梦想都能实现 | 来源:发表于2016-12-21 10:48 被阅读0次
    class Solution(object):
        def lastRemaining(self, n):
            """
            :type n: int
            :rtype: int
            """
    
            if not n: return 0
            start, step,count=1,1,n
            end=start+(count-1)*step
            direction=1
            while count>1:
                if direction==1:
                    start,step,count=start+step,step*2,count/2
                    end=start+(count-1)*step
                else:
                    end,step,count=end-step,step*2,count/2
                    start=end-(count-1)*step
                direction*=-1
            return start 
                
    

    相关文章

      网友评论

          本文标题:390. Elimination Game

          本文链接:https://www.haomeiwen.com/subject/focqvttx.html