import java.util.*; public class Solution { /** * * @param prices int整型一维数组 * @return int整型 */ public int maxProfit (int[] prices) { // write code here int res = 0; int min = prices[0]; int max = prices[0]; int min_index = 0; int max_index = 0; for(int i=1;i<prices.length;i++){ if(prices[i]>max&&i>min_index){ max=prices[i]; max_index = i; int temp = max - min; if(temp>res){ res=temp; } } if(prices[i]<min){ min = prices[i]; min_index = i; max = min; max_index=i; } } return res; } }