Skip to content

Commit 2ebf0e3

Browse files
committed
Runtime: 98 ms (Top 16.21%) | Memory: 43.4 MB (Top 87.12%)
1 parent e0f99fe commit 2ebf0e3

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1+
// Runtime: 98 ms (Top 16.21%) | Memory: 43.4 MB (Top 87.12%)
12
class Solution {
23
public String minWindow(String s, String t) {
34
HashMap<Character, Integer> child = new HashMap<>();
45
HashMap<Character, Integer> parent = new HashMap<>();
5-
6+
67
int left = -1, right = -1, match = 0;
78
String window = "";
8-
9+
910
for(int i = 0; i < t.length(); i++){
10-
char c = t.charAt(i);
11-
child.put(c, child.getOrDefault(c, 0) + 1); //Child frequency map
11+
char c = t.charAt(i);
12+
child.put(c, child.getOrDefault(c, 0) + 1); //Child frequency map
1213
}
13-
14+
1415
while(true){
1516
boolean f1 = false, f2 = false;
16-
17+
1718
while(right < s.length() - 1 && match < t.length()){
1819
right++;
1920
char c = s.charAt(right);
20-
parent.put(c, parent.getOrDefault(c, 0) + 1); // Acquiring characters till
21-
if(parent.getOrDefault(c, 0) <= child.getOrDefault(c, 0)) // match count is equal
21+
parent.put(c, parent.getOrDefault(c, 0) + 1); // Acquiring characters till
22+
if(parent.getOrDefault(c, 0) <= child.getOrDefault(c, 0)) // match count is equal
2223
match++;
23-
24+
2425
f1 = true;
2526
}
2627
while(left < right && match == t.length()){
2728
String potstring = s.substring(left + 1, right + 1);
2829
if(window.length() == 0 || window.length() > potstring.length())
29-
window = potstring; //Calculating length of window
30-
30+
window = potstring; //Calculating length of window
31+
3132
left++;
3233
char c = s.charAt(left);
3334
parent.put(c, parent.getOrDefault(c, 0) - 1);
34-
if(parent.get(c) == 0) //Releasing characters by
35-
parent.remove(c); //left pointer for finding smallest window
36-
35+
if(parent.get(c) == 0) //Releasing characters by
36+
parent.remove(c); //left pointer for finding smallest window
37+
3738
if(parent.getOrDefault(c, 0) < child.getOrDefault(c, 0))
3839
match--;
39-
40+
4041
f2 = true;
4142
}
42-
43+
4344
if(f1 == false && f2 == false)
4445
break;
4546
}
46-
47-
47+
4848
return window;
4949
}
50-
}
50+
}

0 commit comments

Comments
 (0)