Anagrams @ LeetCode (Python)
Unique Binary Search Trees @ LeetCode (Python)

Jump Game @ LeetCode (Python)

kitt posted @ 2014年2月18日 02:03 in LeetCode , 3139 阅读

用一个变量记录最大可到达的位置, 每次在这个位置之前找。

class Solution:
    # @param A, a list of integers
    # @return a boolean
    def canJump(self, A):
        lenA = len(A)
        canReach = 0
        for i in xrange(lenA):
            if i <= canReach:
                canReach = max(canReach, i + A[i])
                if canReach >= lenA - 1: return True
        return False

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter