Skip to content

Commit 99a05a0

Browse files
committed
FEAT : 2 problems solved
1 parent d52bb73 commit 99a05a0

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def maxProfit(self, prices: list[int]) -> int:
3+
min_p = prices[0]
4+
cur = 0
5+
max_p = 0
6+
for n in prices:
7+
if n < min_p:
8+
min_p = n
9+
cur = n - min_p
10+
if max_p < cur:
11+
max_p = cur
12+
13+
return max_p
14+
15+

group-anagrams/aa601.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def groupAnagrams(self, strs: list[str]) -> list[list[str]]:
3+
ans = {}
4+
5+
for word in strs:
6+
# 단어의 문자를 정렬 후 키로 사용
7+
sortedWord = ''.join(sorted(word))
8+
# 초기 리스트 생성
9+
if sortedWord not in ans:
10+
ans[sortedWord] = []
11+
ans[sortedWord].append(word)
12+
13+
# 딕셔너리의 value를 list로 변환
14+
ansLst = list(ans.values())
15+
return ansLst
16+

0 commit comments

Comments
 (0)