Skip to content

Commit 3764345

Browse files
Refactor variable names for clarity in minimum window logic.
Replaced ambiguous variable names with more descriptive ones, such as renaming `window_length` to `min_window_length`. These changes improve code readability and make the logic easier to understand for future maintenance.
1 parent 3b78c2e commit 3764345

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Sliding Window/minimum_window_substring.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def min_window(s: str, t: str) -> str:
1414
if m > n:
1515
return ''
1616

17-
result = float('inf'), None, None # (window length, left, right)
17+
result = float('inf'), None, None # (minimum window length, left, right)
1818

1919
# Count characters in t
2020
t_counts = Counter(t)
@@ -40,8 +40,10 @@ def min_window(s: str, t: str) -> str:
4040
char = s[left]
4141

4242
# Save the smallest window until now
43-
if right - left + 1 < result[0]:
44-
result = (right - left + 1), left, right
43+
min_window_length = result[0]
44+
current_window_length = right - left + 1
45+
if current_window_length < min_window_length:
46+
result = current_window_length, left, right
4547

4648
# The character at the position by the 'left' pointer is no longer a part of the window
4749
window_counts[char] -= 1
@@ -52,9 +54,9 @@ def min_window(s: str, t: str) -> str:
5254
# Move the left pointer forward
5355
left += 1
5456

55-
window_length = result[0]
57+
min_window_length = result[0]
5658

57-
if window_length == float('inf'):
59+
if min_window_length == float('inf'):
5860
return ''
5961

6062
# Build the result

0 commit comments

Comments
 (0)