摘要: func maxProfit(prices []int) int { length := len(prices) // 特殊判断 if length <= 1 { return 0 } // 声明dp dp := make([][3]int, length) //dp[i][j]表示[0, i]区间 阅读全文
posted @ 2020-07-27 20:43 柠檬橘 阅读(79) 评论(0) 推荐(0) 编辑
摘要: func maxProfit(prices []int) int { max:=0 for i:=1;i<len(prices);i++{ if prices[i]>prices[i-1]{ max+=prices[i]-prices[i-1] } } return max } 下面这个有点不好ai 阅读全文
posted @ 2020-07-27 18:31 柠檬橘 阅读(108) 评论(0) 推荐(0) 编辑
摘要: func Max(i, j int) int { if i > j { return i } return j } func maxProfit(prices []int) int { pLen := len(prices) k := 2 if pLen < 1 { return 0 } //买卖股 阅读全文
posted @ 2020-07-27 18:11 柠檬橘 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 买卖股票的最佳时机 简单,注释都可不用 前i天的最大收益 = max{前i-1天的最大收益,第i天的价格-前i-1天中的最小价格 func maxProfit(prices []int) int { max:=0 prof:=0 for j:=0;j<len(prices);j++{ for i:= 阅读全文
posted @ 2020-07-27 17:38 柠檬橘 阅读(116) 评论(0) 推荐(0) 编辑