Skip to content

Commit 27d6f0b

Browse files
Update MinimumWindowSubstring.java
1 parent 1d2d6d7 commit 27d6f0b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/main/java/com/thealgorithms/slidingwindow/MinimumWindowSubstring.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ private MinimumWindowSubstring() {
2525
* @return the minimum sum of the subarray of size k
2626
*/
2727
public static String minWindow(String s, String t) {
28-
if (s.length() < t.length()) return "";
28+
if (s.length() < t.length())
29+
{
30+
return "";
31+
}
2932

3033
HashMap<Character, Integer> tFreq = new HashMap<>();
3134
for (char c : t.toCharArray()) {
3235
tFreq.put(c, tFreq.getOrDefault(c, 0) + 1);
3336
}
3437

3538
HashMap<Character, Integer> windowFreq = new HashMap<>();
36-
int left = 0, right = 0, minLen = Integer.MAX_VALUE, count = 0;
39+
int left = 0;
40+
int right = 0;
41+
int minLen = Integer.MAX_VALUE;
42+
int count = 0;
3743
String result = "";
3844

3945
while (right < s.length()) {
@@ -43,7 +49,6 @@ public static String minWindow(String s, String t) {
4349
if (tFreq.containsKey(c) && windowFreq.get(c).intValue() <= tFreq.get(c).intValue()) {
4450
count++;
4551
}
46-
4752
while (count == t.length()) {
4853
if (right - left + 1 < minLen) {
4954
minLen = right - left + 1;
@@ -52,7 +57,6 @@ public static String minWindow(String s, String t) {
5257

5358
char leftChar = s.charAt(left);
5459
windowFreq.put(leftChar, windowFreq.get(leftChar) - 1);
55-
5660
if (tFreq.containsKey(leftChar) && windowFreq.get(leftChar) < tFreq.get(leftChar)) {
5761
count--;
5862
}

0 commit comments

Comments
 (0)