Skip to content

Commit 23331b2

Browse files
Use for loop instead of while in sliding window logic.
Refactored the character addition loop to use a `for` loop instead of a `while` loop, simplifying the control flow. Removed an unnecessary window expansion step, making the code cleaner and more concise without altering the functionality.
1 parent 0987c28 commit 23331b2

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

Sliding Window/minimum_window_substring.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def min_window(s: str, t: str) -> str:
2727
window_counts = defaultdict(int)
2828
window = ''
2929

30-
while right < n:
30+
for right in range(n):
3131
# Add one character from the right to the window
3232
char = s[right]
3333
window_counts[char] += 1
@@ -54,9 +54,6 @@ def min_window(s: str, t: str) -> str:
5454
# Move the left pointer forward
5555
left += 1
5656

57-
# Expand the window
58-
right += 1
59-
6057
if result[0] == float('inf'):
6158
return ''
6259

0 commit comments

Comments
 (0)