| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 3줄정리
- 스탭퍼
- 운동
- 매일
- 개발자
- Problem Solving
- 10분
- 사이드
- 잡생각
- 읽기
- 30분
- 월간
- Daily Challenge
- 괜찮음
- 영어원서읽기
- FIT XR
- 만화도
- 쓰릴오브파이트
- 링피트
- 파비최
- 프로젝트
- leetcode
- English
- 미드시청
- realclass
- 리얼 클래스
- 뭐든
- Writing
- 화상영어
- 영어공부
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.01.27 Today's Challenge 본문
https://leetcode.com/problems/concatenated-words/
Concatenated Words - LeetCode
Concatenated Words - Given an array of strings words (without duplicates), return all the concatenated words in the given list of words. A concatenated word is defined as a string that is comprised entirely of at least two shorter words in the given array.
leetcode.com
class Solution:
def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]:
def can(w, dit):
for i in range(mini, len(w)):
lf = w[:i]
rt = w[i:]
if lf in dit:
if rt in dit or can(rt, dit):
return True
return False
res = []
dit = set(list(words))
mini = 10000
for w in words:
mini = min(len(w), mini)
for w in words:
if can(w, dit):
res.append(w)
return res반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| 2023.01.29 Today's Challenge (0) | 2023.01.29 |
|---|---|
| 2023.01.28 Today's Challenge (0) | 2023.01.28 |
| 2023.01.26 Today's Challenge (0) | 2023.01.26 |
| 2023.01.25 Today's Challenge (0) | 2023.01.25 |
| 2023.01.24 Today's Challenge (0) | 2023.01.24 |
Comments