Feedback on Python Implementation Please!


  • 0
    C

    Hello, I am very new to the LeetCode community so go easy on me please! I would like some feedback on my approach. This is the textbook approach that I learned to use for approaching DP problems. How do you think an interviewer would react to something like this? Would they have preferred I did something a little more robust looking or would this be acceptable.

        class Solution(object):
            
            def rob(self, nums):
                # 0 = Don't rob home
                # 1 = Rob home
                dpTable = [[0 for x in range(len(nums) + 1)], [0 for x in range(len(nums) + 1)]
                
                for i in range(1,len(nums) + 1):
                    dpTable[0][i] = max(dpTable[0][i - 1], dpTable[1][i-1])
                    dpTable[1][i] = dpTable[0][i-1] + nums[i-1]
    
                return max(dpTable[0][len(nums)], dpTable[1][len(nums)])

Log in to reply
 

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