赞
踩
题目:
题解:
- func rob(nums []int) int {
- if len(nums) == 0 {
- return 0
- }
- if len(nums) == 1 {
- return nums[0]
- }
- first := nums[0]
- second := max(nums[0], nums[1])
- for i := 2; i < len(nums); i++ {
- first, second = second, max(first + nums[i], second)
- }
- return second
- }
-
- func max(x, y int) int {
- if x > y {
- return x
- }
- return y
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。