题解 | #牛群售价预测#
牛群售价预测
https://www.nowcoder.com/practice/bbdb8d6f3a2e434e87f749358d16d653
package main
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param prices int整型一维数组
* @return int整型
*/
func max_profit( prices []int ) int {
// write code here
minpri,maxpro :=prices[0],0
for i:=1;i<len(prices);i++{
maxpro=max(maxpro,prices[i]-minpri)
minpri=min(minpri,prices[i])
}
return maxpro
}
func max(a,b int)int{
if a>b{
return a
}
return b
}
func min(a,b int)int{
if a>b{
return b
}
return a
}
查看13道真题和解析