import java.util.*; public class Solution { /** * * @param prices int整型一维数组 * @return int整型 */ public int maxProfit (int[] prices) { // write code here if(prices.length < 2){ return 0; } int maxP = prices[1] - prices[0]; for(int i =0;i<prices.length - 1;i++){ int next = prices[i]; for(int j = i + 1;j<prices.length;j++){ maxP = Math.max(maxP,(prices[j] - next)); } } if(maxP < 0){ return 0; } return maxP; } }