题解 | #牛群售价预测#

牛群售价预测

https://www.nowcoder.com/practice/bbdb8d6f3a2e434e87f749358d16d653

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param prices int整型一维数组 
     * @return int整型
     */
    public int max_profit (int[] prices) {
        // write code here
        int profit = 0;
        int minp = prices[0];
        for(int i=1;i<prices.length;i++){
            if(prices[i]<minp){
                minp=prices[i];
            }else{
                profit = Math.max(profit,prices[i]-minp);
            }
        }
        return profit;
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务