Problem
Solution
class Solution:
def maxProfit(self, prices: List[int]) -> int:
low = -1
profit = 0
for price in prices:
if price < low:
low = price
continue
if price - low > profit:
if low < 0:
low = price
else:
profit = price - low
return profit
Time Complexity
O(N)
Space Complexity
O(1)
'CODE > Algorithms & Data Structures' 카테고리의 다른 글
[Coderust] Implementation of Linked List (0) | 2022.03.08 |
---|---|
[Coderust] Merge an Array With Overlapping Intervals (0) | 2022.02.28 |
[Coderust] Move All Zeros to the Beginning of the Array (0) | 2022.02.25 |
[Coderust] Find First and Last Position of Element in Sorted Array (0) | 2022.02.24 |
[Coderust] Rotate Array (0) | 2022.02.23 |