(int[] prices)
| 11 | */ |
| 12 | public class Solution { |
| 13 | public int maxProfit(int[] prices) { |
| 14 | int max = 0, minPrice = Integer.MAX_VALUE; |
| 15 | for (int i = 0; i < prices.length; ++i) { |
| 16 | if (prices[i] < minPrice) minPrice = prices[i]; |
| 17 | int delta = prices[i] - minPrice; |
| 18 | if (delta > max) max = delta; |
| 19 | } |
| 20 | return max; |
| 21 | } |
| 22 | |
| 23 | public static void main(String[] args) { |
| 24 | Solution solution = new Solution(); |