My python solution

  • 1
    class Solution:
        # @param num, a list of integer
        # @return an integer
        def rob(self, num):
            if not num: return 0
            n = len(num)
            if n==1: return num[0]
            dp = [0]*n
            dp[0],dp[1] = num[0],max(num[1],num[0])
            for i in xrange(2,n):
            return dp[n-1]

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.