leetcode 789

我觉得这题不好,比较无厘头。这题主要是看自己到达目标的时候会不会碰见鬼。一个直观的想法是,如果我到达目标需要的步数比所有的鬼到达目标需要的步数都要小,那么我就能够成功到达目标,反之,就不能成功到达目标。虽然我也没有严格的依据和证明,但感觉就是这样,附代码:

class Solution:
    def escapeGhosts(self, ghosts, target):
        """
        :type ghosts: List[List[int]]
        :type target: List[int]
        :rtype: bool
        """
        step_o = abs(target[0])+abs(target[1])
        for temp in ghosts:
            step_t = abs(temp[0] - target[0]) + abs(temp[1] - target[1])
            if step_t <= step_o:
                return False
        return True

猜你喜欢

转载自blog.csdn.net/bengepai/article/details/82590944