121. Best Time to Buy and Sell Stock
Description
See https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
Solution
Pretty straight forward problem and solution. Iterate through the array looking for a lower price than the current one (which is initialized to the first element in the list). Profit is the difference between the current item and the lowest price. Keep track of the max profit.
Space O(1), Time O(N)
Last updated