[LeetCode][Python3] 76. Minimum Window Substring
2019. 4. 16. 02:37 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/minimum-window-substring/
My Solution :
class Solution:
def minWindow(self, s: str, t: str) -> str:
t_cnt = dict()
for c in t:
t_cnt[c] = t_cnt.get(c, 0) + 1
remain = len(t)
left = right = 0
ans = ''
while right < len(s):
c = s[right]
if c in t_cnt:
if t_cnt[c] > 0:
remain -= 1
t_cnt[c] -= 1
right += 1
while remain == 0:
if not ans or len(ans) > right - left:
ans = s[left:right]
c = s[left]
if c in t_cnt:
if t_cnt[c] == 0:
remain += 1
t_cnt[c] += 1
left += 1
return ans
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 152. Maximum Product Subarray (0) | 2019.04.22 |
---|---|
[LeetCode][Python3] 124. Binary Tree Maximum Path Sum (0) | 2019.04.20 |
[LeetCode][Python3] 322. Coin Change (0) | 2019.04.20 |
[LeetCode][Python3] 54. Spiral Matrix (0) | 2019.04.18 |
[LeetCode][Python3] 84. Largest Rectangle in Histogram (0) | 2019.04.15 |
[LeetCode][Python3] 79. Word Search (0) | 2019.04.13 |
[LeetCode][Python3] 313. Super Ugly Number (0) | 2019.04.13 |
[LeetCode][Python3] 218. The Skyline Problem (0) | 2019.04.11 |
최근에 달린 댓글 최근에 달린 댓글