You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/**Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string "".
2
+
3
+
The testcases will be generated such that the answer is unique.
4
+
5
+
A substring is a contiguous sequence of characters within the string. */
6
+
7
+
/**
8
+
* @param {string} s
9
+
* @param {string} t
10
+
* @return {string}
11
+
*/
12
+
varminWindow=function(s,t){
13
+
constmap=newMap()
14
+
for(leti=0;i<t.length;i++){
15
+
map.set(t[i],(map.get(t[i])||0)+1)
16
+
}
17
+
18
+
letcount=1
19
+
letstart=0
20
+
while(start<s.length&&!map.has(s[start])){
21
+
start++
22
+
}
23
+
if(start===s.length){
24
+
return''
25
+
}
26
+
if(t.length===1){
27
+
returns[start]
28
+
}
29
+
map.set(s[start],map.get(s[start])-1)
30
+
31
+
letminStart=start
32
+
letminEnd=s.length
33
+
34
+
for(end=start+1;end<s.length;end++){
35
+
if(map.has(s[end])){
36
+
letendCount=map.get(s[end])
37
+
map.set(s[end],--endCount)
38
+
// endCount < 0 means there are too many s[end] within the window.
39
+
if(endCount>=0){
40
+
count++
41
+
}
42
+
43
+
// There could be too may s[start] within the window.
44
+
// So after dumping the first s[start] the window might still be full.
0 commit comments