2*dp 2*bit
This commit is contained in:
		
							
								
								
									
										16
									
								
								198-240603-pass/main.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								198-240603-pass/main.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| class Solution: | ||||
|     def rob(self, nums: list[int]) -> int: | ||||
|         s = [] | ||||
|         rlt = -1e6 | ||||
|         for i, num in enumerate(nums): | ||||
|             maxi = num | ||||
|             for j in range(0, i - 1, 1): | ||||
|                 maxi = max(s[j] + num, maxi) | ||||
|             s.append(maxi) | ||||
|             rlt = max(maxi, rlt) | ||||
|         return rlt | ||||
|  | ||||
| sol = Solution() | ||||
| print(sol.rob([1, 2, 3, 1])) | ||||
| print(sol.rob([2, 7, 9, 3, 1])) | ||||
| print(sol.rob([2, 7, 9, 9, 3, 1])) | ||||
		Reference in New Issue
	
	Block a user