题解 | #牛奶价格预测#
牛奶价格预测
https://www.nowcoder.com/practice/9a08dfa990e94c0c98fd0bf197c87480
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param milkPrices int整型一维数组 * @return int整型 */ public int maxProfit (int[] milkPrices) { // write code here int min_value=milkPrices[0]; int ans=0; for(int i=1;i<milkPrices.length;i++){ if(milkPrices[i]>min_value){ ans=Math.max(ans,milkPrices[i]-min_value); } else min_value=milkPrices[i]; } return ans; } }