We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents f1f3e4e + 9baac3a commit 2940e67Copy full SHA for 2940e67
best-time-to-buy-and-sell-stock/jeldo.py
@@ -0,0 +1,9 @@
1
+class Solution:
2
+ # O(n), n = len(prices)
3
+ def maxProfit(self, prices: List[int]) -> int:
4
+ min_price = float('inf')
5
+ profit = 0
6
+ for price in prices:
7
+ min_price = min(min_price, price)
8
+ profit = max(profit, price - min_price)
9
+ return profit
group-anagrams/jeldo.py
@@ -0,0 +1,10 @@
+from collections import defaultdict
+
+ # O(n*mlogm), n = len(str), m = the length of the longest string
+ def groupAnagrams(self, strs: list[str]) -> list[list[str]]:
+ group = defaultdict(list)
+ for s in strs:
+ group[''.join(sorted(s))].append(s)
10
+ return list(group.values())
0 commit comments