classSolution:defrob(self,nums: List[int]) ->int:iflen(nums)==0:return0iflen(nums)==1:return nums[0] res1 = self._run_rob(nums, 0, len(nums)-2) res2 = self._run_rob(nums, 1, len(nums)-1)returnmax(res1, res2)def_run_rob(self,nums,start,end): # 左闭右闭if end == start:return nums[start] pre = nums[start] cur =max(nums[start], nums[start+1])for i inrange(start+2, end+1): tmp = cur cur =max(pre+nums[i], cur) pre = tmpreturn cur