1
2public int largestProfit(int[] prices) {
3 int profit = 0;
4 int min = Integer.MAX_VALUE;
5 for(int i = 0; i < prices.length; i++) {
6 if (prices[i] > min) {
7 profit = Math.max(profit, prices[i] - min);
8 } else {
9 min = prices[i];
10 }
11 }
12
13 return profit;
14}
15
16