Longest Substring Without Repeat · Nhóm: Cửa sổ trượt
Đoạn con không lặp dài nhất (Longest Substring Without Repeat), nhóm Cửa sổ trượt.
def length_of_longest(s):
window = set()
lo = 0
best = 0
for hi in range(len(s)):
while s[hi] in window:
window.remove(s[lo])
lo += 1
window.add(s[hi])
best = max(best, hi - lo + 1)
return best
Mở trang để xem mô phỏng từng bước và xuất slide bài giảng.