Skip to content

Commit e0bcd63

Browse files
Update algorithms/dynamic_programming/buy_sell_stock/__init__.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 40b083a commit e0bcd63

File tree

1 file changed

+12
-1
lines changed
  • algorithms/dynamic_programming/buy_sell_stock

1 file changed

+12
-1
lines changed

algorithms/dynamic_programming/buy_sell_stock/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,19 @@ def max_profit_two_pointers(prices: List[int]) -> int:
3333
Space: O(1), no extra memory is used
3434
Time: O(n), where n is the size of the input list & we iterate through the list only once
3535
"""
36+
def max_profit_two_pointers(prices: List[int]) -> int:
37+
"""
38+
Variation of max_profit using 2 pointers
39+
Complexity Analysis:
40+
Space: O(1), no extra memory is used
41+
Time: O(n), where n is the size of the input list & we iterate through the list only once
42+
"""
43+
if prices is None or len(prices) < 2:
44+
return 0
45+
3646
number_of_prices = len(prices)
37-
if prices is None or number_of_prices < 2:
47+
48+
left, right = 0, 1
3849
return 0
3950

4051
left, right = 0, 1

0 commit comments

Comments
 (0)