Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 코딩테스트 준비
- 빈 충돌
- 개발자 취업
- 취업리부트코스
- TiL
- 커스텀 헤더
- 개발자부트캠프추천
- JavaScript
- 파이썬
- Spring multimodule
- 단기개발자코스
- 항해99
- KPT회고
- jwttoken
- 1주일회고
- infcon 2024
- 빈 조회 2개 이상
- 구글 OAuth login
- @FeignClient
- Python
- spring batch 5.0
- 전략패턴 #StrategyPattern #디자인패턴
- 디자인패턴
- 프로그래머스
- 프로그래머스 이중우선순위큐
- 99클럽
- 인프콘 2024
- 디자인 패턴
- DesignPattern
- jwt
Archives
- Today
- Total
m1ndy5's coding blog
LeetCode 49. Group Anagrams with Python 본문
https://leetcode.com/problems/group-anagrams/
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
dic = {}
for word in strs:
# 알파벳 순으로 정렬(ate -> aet)
w = ''.join(sorted(word))
if w not in dic:
dic[w] = [word]
else:
dic[w].append(word)
return list(dic.values())
Python sorted
병합 정렬 + 삽입 정렬 아이디어를 더한 하이브리드 방식
O(NlogN)의 시간복잡도를 가짐
정렬된 결과를 리스트 자료형으로 반환한다.
'알고리즘 with python > 알고리즘 스터디' 카테고리의 다른 글
LeetCode 15. 3Sum with Python (2) | 2024.01.03 |
---|---|
LeetCode 5. Longest Palindromic Substring with Python (1) | 2024.01.03 |
프로그래머스 경주로 건설 with Python (0) | 2023.12.20 |
프로그래머스 보석 쇼핑(투포인터 알고리즘) with Python (1) | 2023.12.19 |
프로그래머스 리코쳇 로봇 with python (1) | 2023.12.12 |