小黑代码(思路优于官方题解)
class Solution:
def minWindow(self, s: str, t: str) -> str:
# 字符串长度
n_s = len(s)
n_t = len(t)
# 没有找到
if n_t > n_s:
return ''
# 计数变量
map_count = collections.Counter(t)
map_ = collections.Counter(t)
map_windows = collections.defaultdict(int)
count = n_t
# 定义头尾指针
head = 0
tail = 0
# 初始化变量
is_first = True
# 结果变量
result = n_s
result_s = ''
while tail < n_s:
# 寻找初始位置
while is_first and tail < n_s:
map_windows[s[tail]] += 1
if map_[s[tail]]:
count -= 1
map_[s[tail]] -= 1
tail += 1
if not count:
count = n_t
result = tail - head
result_s = s[head:tail]
is_first = False
break
if is_first:
break
# 右指针右移动
while tail < n_s and count < n_t:
if map_windows[s[tail]] < map_count[s[tail]]:
count += 1
map_windows[s[tail]] += 1
tail += 1
# 左指针右移动
while count == n_t:
if map_windows[s[head]] == map_count[s[head]]:
count -= 1
map_windows[s[head]] -= 1
if tail - head < result:
result = tail - head
result_s = s[head:tail]
head += 1
return result_s
喜茶店学完了算法,准备回家吃饭
续费换地方,钢琴练习《知更鸟罗宾》
去常营练琴,吃DQ
下午赶往大兴机场
坐上了大飞机,全坐满了
(看到了雪峰)
到达乌鲁木齐地窝堡国际机场,节俭的我们吃泡面充饥
到达东方王朝酒店,价格惊到我们了
前往大巴扎小吃街吃晚饭
(羊肉大串)
(烤蛋)
(冰碴子)
(小羊腿)
(手抓羊肉)
(肉馕)
(乌鲁木齐棒棒的治安,跟警察和警犬合一个影)
day1早餐
坐大巴车到达天山天池景区
坐景区接驳车上去
到达天山天池,深吸气
(看到可爱小松鼠)
游览天山天池
午饭下山后的团餐
驱车7小时去布尔津,穿越准葛尔盆地沙漠
(遇到沙尘暴)
游览五彩滩景区,被小咬蚊子折磨的够够的
(感谢本科新疆同学的推荐)
来到布尔津酒店