일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 운영체제
- shiba
- 프로그래머스
- Python Code
- Class
- LeetCode
- iterator
- Python
- DWG
- Protocol
- 컴퓨터의 구조
- concurrency
- Decorator
- 43. Multiply Strings
- Regular Expression
- 109. Convert Sorted List to Binary Search Tree
- Python Implementation
- Generator
- attribute
- t1
- 파이썬
- data science
- Convert Sorted List to Binary Search Tree
- kaggle
- Substring with Concatenation of All Words
- 315. Count of Smaller Numbers After Self
- 밴픽
- 715. Range Module
- 30. Substring with Concatenation of All Words
- 시바견
- Today
- Total
목록30. Substring with Concatenation of All Words (2)
Scribbling
A solution using sliding window. class Solution: def findSubstring(self, s: str, words: List[str]) -> List[int]: from collections import Counter ret = [] wordSet = set(words) n, m = len(words), len(words[0]) for i in range(m): wordCounter = Counter(words) k = j = i while j + m = n * m: if s[k:k+m] in wordSet: wordCounter[s[k:k+m]] += 1 k += m word = s[j:j+m] if word in wordSet: wordCounter[word]..
O(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