Skip to content

Commit 189ba88

Browse files
authored
Merge pull request #2176 from mandel-17/main
[mandel-17] WEEK 05 solutions
2 parents 8cab3e1 + ded9dcc commit 189ba88

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import List
2+
3+
class Solution:
4+
def maxProfit(self, prices: List[int]) -> int:
5+
min_price = prices[0]
6+
max_price = prices[0]
7+
temp_min = prices[0]
8+
diff = 0
9+
for price in prices:
10+
temp_diff = price - temp_min
11+
if temp_diff < 0:
12+
temp_min = price
13+
elif temp_diff > diff:
14+
max_price = price
15+
min_price = temp_min
16+
diff = temp_diff
17+
else:
18+
continue
19+
return diff
20+

group-anagrams/mandel-17.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import collections
2+
from typing import List
3+
4+
class Solution:
5+
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
6+
result = collections.defaultdict(list)
7+
for s in strs:
8+
result[''.join(sorted(s))].append(s)
9+
return list(result.values())
10+

0 commit comments

Comments
 (0)