[Java] Runtime: 1ms, faster than 100% || O(n) time & O(1) space
\nclass Solution {\n    public int maxProfit(int[] prices) {\n        int minBuy = prices[0], maxProfit = 0;\n        for (int current : prices) {\n            
```\nclass Solution {\n    public int maxProfit(int[] prices) {\n        int minBuy = prices[0], maxProfit = 0;\n        for (int current : prices) {\n            minBuy = Math.min(minBuy, current);\n            maxProfit = Math.max(maxProfit, current - minBuy);\n        }\n        return maxProfit;\n    }\n}\n```\n\n![image](https://assets.leetcode.com/users/images/302b12c8-9225-4955-8376-ddc8de15ccd5_1667962964.2372463.png)\n
['Java']