首页 > 其他 > 详细

leetcode 754 到达终点数字

时间:2019-05-14 20:03:06      阅读:153      评论:0      收藏:0      [点我收藏+]

https://blog.csdn.net/u012737193/article/details/78951070

class Solution(object):
    def reachNumber(self, target):
        """
        :type target: int
        :rtype: int
        """
        target = abs(target)
        i = 0
        ans = 0
        while ans < target:
            i += 1
            ans += i
        dt = ans - target
        if ans == target:
            return i
        if dt%2 == 0:
            return i
        else:
            if i % 2 == 0:
                return i+1
            else:
                return i+2
        
        return i+1

 

leetcode 754 到达终点数字

原文:https://www.cnblogs.com/woshizhizhang/p/10864004.html

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