일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Substring with Concatenation of All Words
- 컴퓨터의 구조
- 30. Substring with Concatenation of All Words
- 운영체제
- iterator
- Decorator
- LeetCode
- attribute
- Convert Sorted List to Binary Search Tree
- 315. Count of Smaller Numbers After Self
- 43. Multiply Strings
- t1
- shiba
- DWG
- 밴픽
- Class
- concurrency
- kaggle
- 파이썬
- data science
- Regular Expression
- Python Code
- Generator
- 프로그래머스
- 시바견
- 715. Range Module
- 109. Convert Sorted List to Binary Search Tree
- Python Implementation
- Protocol
- Python
- 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