일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
Tags
- 리얼 클래스
- 사이드
- leetcode
- Daily Challenge
- 미드시청
- 링피트
- 매일
- 프로젝트
- 만화도
- 뭐든
- 10분
- 읽기
- 영어원서읽기
- 스탭퍼
- 화상영어
- Problem Solving
- 괜찮음
- 쓰릴오브파이트
- 운동
- 영어공부
- 잡생각
- 파비최
- 30분
- 월간
- 개발자
- realclass
- English
- FIT XR
- Writing
- 3줄정리
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/find-duplicate-file-in-system/
Find Duplicate File in System - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
딱 봤을 땐, 어려워 보이는데
그냥 해쉬 맵 써서 풀면 끝.
class Solution:
def findDuplicate(self, paths: List[str]) -> List[List[str]]:
m = {}
for path in paths:
s_path = path.split()
root = s_path[0]
for file in s_path[1:]:
file_name, content = file.split('(')
full_path = root + '/' + file_name
if content in m:
m[content].append(full_path)
else:
m[content] = [full_path]
ans = []
for content in m:
if len(m[content]) > 1:
ans.append(m[content])
return ans
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.09.21 |
---|---|
Today's Challenge (2) | 2022.09.20 |
Today's Challenge (0) | 2022.09.18 |
Today's Challenge (0) | 2022.09.17 |
Today's Challenge (0) | 2022.09.16 |
Comments