Java Code to find best time to buy and sell stocks.
Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(n)\n\n- Space complexity:\n Add your space complexity here, e.g. O(n) \nO(1)\n\n# 
# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$\n\n# Code\n```\nclass Solution {\n    public int maxProfit(int[] prices) {\n        int left = 0, right = 1,max = 0;\n        while(right < prices.length){\n            if(prices[left] > prices[right]){\n                left = right;\n            }else if(prices[left] < prices[right]){\n                max = Math.max(max,(prices[right] - prices[left]));\n            }\n            right++;\n        }\n        return max;\n    }\n}\n```\n\n## **If you find this helpful, please upvote \uD83D\uDE0A**
['Two Pointers', 'Java']