import java.util.*;
public class Solution {
/**
*
* @param prices int整型一维数组
* @return int整型
*/
public int maxProfit (int[] prices) {
// write code here
if(prices.length == 0){
return 0;
}
int[] profit = new int[prices.length];
int lowerPrice = prices[0];
for(int i = 0; i < prices.length; i++){
if(prices[i] > lowerPrice){
profit[i] = prices[i] - lowerPrice;
}
else {
profit[i] = 0;
lowerPrice = prices[i];
}
}
Arrays.sort(profit);
return profit[profit.length - 1];
}
}