Skip to content

Commit 7d6d325

Browse files
Refactor window shrinking logic in minimum window substring.
Clarified comments for the window shrinking process to improve code readability. Added an explanation for updating `matched_characters` when the window state changes. No functional changes were made.
1 parent 463b339 commit 7d6d325

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

Sliding Window/minimum_window_substring.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ def min_window(s: str, t: str) -> str:
4646
result = current_window_length, left, right
4747

4848
# The character at the position by the 'left' pointer is no longer a part of the window
49+
# Therefore, shrink the window
4950
window_counts[char] -= 1
5051
window = remove_leftmost_occurrence(window, char)
52+
53+
# If we are not in a 'desirable' state, decrement 'matched_characters'
5154
if char in t_counts and window_counts[char] < t_counts[char]:
5255
matched_characters -= 1
5356

0 commit comments

Comments
 (0)