版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
package program;
/**
* @Auther: 大哥的叔
* @Date: 2019/10/1 17:22
* @Description:
*/
public class Price {
public static void main (String[] args) {
int [] a={7,1,5,3,6,4};
Price price = new Price();
price.maxProfit(a);
}
public int maxProfit(int[] prices) {
int len = prices.length;
int min = Integer.MAX_VALUE;
int max= 0;
for (int i = 0; i <len ; i++) {
if (prices[i]<min){
min = prices[i];
}
else if(prices[i]-min>max){
max =prices[i]-min;
}
}
System.out.println(max);
return max;
}
}