Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions best-time-to-buy-and-sell-stock/mandel-17.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import List

class Solution:
def maxProfit(self, prices: List[int]) -> int:
min_price = prices[0]
max_price = prices[0]
temp_min = prices[0]
diff = 0
for price in prices:
temp_diff = price - temp_min
if temp_diff < 0:
temp_min = price
elif temp_diff > diff:
max_price = price
min_price = temp_min
diff = temp_diff
else:
continue
return diff

10 changes: 10 additions & 0 deletions group-anagrams/mandel-17.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import collections
from typing import List

class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
result = collections.defaultdict(list)
for s in strs:
result[''.join(sorted(s))].append(s)
return list(result.values())