일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Protocol
- t1
- iterator
- 밴픽
- DWG
- 프로그래머스
- Substring with Concatenation of All Words
- 315. Count of Smaller Numbers After Self
- 컴퓨터의 구조
- Python Code
- 43. Multiply Strings
- kaggle
- LeetCode
- Python Implementation
- 30. Substring with Concatenation of All Words
- data science
- Generator
- Convert Sorted List to Binary Search Tree
- 시바견
- shiba
- Class
- concurrency
- Regular Expression
- attribute
- Decorator
- Python
- 운영체제
- 파이썬
- 715. Range Module
- 109. Convert Sorted List to Binary Search Tree
Archives
- Today
- Total
Scribbling
LeetCode: 30. Substring with Concatenation of All Words 본문
Computer Science/Coding Test
LeetCode: 30. Substring with Concatenation of All Words
focalpoint 2021. 8. 29. 18:29O(NK)...
from collections import deque, defaultdict
class Solution:
def findSubstring(self, s: str, words: List[str]) -> List[int]:
n = len(s)
m = len(words)
len_words = len(words[0])
if n < m * len_words:
return []
ret = set()
ans = defaultdict(int)
for word in words:
ans[word] += 1
words = set(words)
for i in range(0, len_words):
comp = defaultdict(int)
q = deque([], maxlen=m)
while i <= n - len_words:
cur = s[i:i+len_words]
if len(q) == m:
popped = q.popleft()
if popped in words:
comp[popped] -= 1
q.append(cur)
if cur in words:
comp[cur] += 1
if comp == ans:
ret.add(i-len_words*(m-1))
i += len_words
return list(ret)
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 29. Divide Two Integers (0) | 2021.09.02 |
---|---|
LeetCode: 50. Pow(x, n) (0) | 2021.09.02 |
LeetCode: 26. Remove Duplicates from Sorted Array (0) | 2021.08.27 |
LeetCode: 24. Swap Nodes in Pairs (0) | 2021.08.26 |
LeetCode: 25. Reverse Nodes in k-Group (0) | 2021.08.25 |