FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/minimumwindowsubstring.java at master · wpande/leetcode · GitHub
wpande
leetcode
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode
/
minimumwindowsubstring.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
59 lines (59 loc) · 1.89 KB
Breadcrumbs
leetcode
/
minimumwindowsubstring.java
Copy path
File metadata and controls
59 lines (59 loc) · 1.89 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
public
class
Solution
{
public
String
minWindow
(
String
s
,
String
t
) {
int
lens
=
s
.
length
();
int
lent
=
t
.
length
();
HashMap
<
Character
,
Integer
>
hm
=
new
HashMap
<
Character
,
Integer
>();
int
cnt
=
0
;
HashMap
<
Character
,
Integer
>
thm
=
new
HashMap
<
Character
,
Integer
>();
for
(
int
i
=
0
;
i
<
lent
;
i
++){
char
ch
=
t
.
charAt
(
i
);
if
(
hm
.
get
(
ch
)!=
null
){
Integer
buf
=
hm
.
get
(
ch
);
hm
.
put
(
ch
,
buf
+
1
);
}
else
hm
.
put
(
ch
,
1
);
}
int
lw
=
0
;
int
rw
=
0
;
int
slw
=
0
;
int
srw
=
0
;
int
minsize
=
Integer
.
MAX_VALUE
;
while
(
rw
<
lens
){
char
ch
=
s
.
charAt
(
rw
);
rw
++;
if
(
hm
.
containsKey
(
ch
)){
if
(
thm
.
get
(
ch
)!=
null
){
int
buf
=
thm
.
get
(
ch
);
thm
.
put
(
ch
,
buf
+
1
);
}
else
thm
.
put
(
ch
,
1
);
if
(
thm
.
get
(
ch
)<=
hm
.
get
(
ch
)){
cnt
++;
if
(
cnt
==
lent
){
while
(
lw
<
rw
&&
cnt
==
lent
){
ch
=
s
.
charAt
(
lw
);
lw
++;
if
(
hm
.
containsKey
(
ch
)){
int
buf
=
thm
.
get
(
ch
);
if
(
hm
.
get
(
ch
)==
buf
)
cnt
--;
if
(
buf
==
1
)
thm
.
remove
(
ch
);
else
thm
.
put
(
ch
,
buf
-
1
);
}
}
if
(
rw
-
lw
<
minsize
){
minsize
=
rw
-
lw
;
slw
=
lw
-
1
;
srw
=
rw
;
}
}
}
}
}
return
s
.
substring
(
slw
,
srw
);
}
}
Back
|
FazBrowse Home
|
New Git URL