We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cf5f6c2 commit fddbef5Copy full SHA for fddbef5
minimum-window-substring/ekgns33.java
@@ -0,0 +1,30 @@
1
+class Solution {
2
+ public String minWindow(String s, String t) {
3
+ int[] freq = new int[128];
4
+ char[] str = s.toCharArray();
5
+ int minL = 0;
6
+ int minLength = Integer.MAX_VALUE;
7
+ int l = 0, r = 0, n = s.length();
8
+ for(char c : t.toCharArray()) {
9
+ freq[c-'A']++;
10
+ }
11
+ int resolved = t.length();
12
+ while(r < n) {
13
+ if(freq[str[r++] - 'A']-- > 0) {
14
+ resolved--;
15
16
+ while(resolved == 0) {
17
+ if(r - l < minLength) {
18
+ minL = l;
19
+ minLength = r - l;
20
21
+ if(freq[str[l] - 'A']++ == 0) {
22
+ resolved++;
23
24
+ l++;
25
26
27
+ if(minLength == Integer.MAX_VALUE) return "";
28
+ return new String(str, minL, minLength);
29
30
+}
0 commit comments