FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Leetcode/0076_Minimum_Window_Substring.cpp at main · Nothing-avil/Leetcode · GitHub
Nothing-avil
/
Leetcode
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
4
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Leetcode
/
0076_Minimum_Window_Substring.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (31 loc) · 1.04 KB
Breadcrumbs
Leetcode
/
0076_Minimum_Window_Substring.cpp
Copy path
File metadata and controls
34 lines (31 loc) · 1.04 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
#
pragma
GCC optimize("Ofast","inline","ffast-math","unroll-loops","no-stack-protector")
#
pragma
GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native","f16c")
class
Solution
{
public:
string
minWindow
(string s, string t) {
ios_base::sync_with_stdio
(
0
), cin.
tie
(
0
), cout.
tie
(
0
);
int
m = t.
length
();
int
n = s.
length
();
vector<
int
>
mp
(
128
,
0
);
int
counter = m, start =
0
;
int
minLength =
INT_MAX
;
int
minStart;
for
(
int
i=
0
; i<m; i++){
mp[t[i]-
'
A
'
]++;
}
for
(
int
end=
0
; end<n; end++){
mp[s[end]-
'
A
'
]--;
if
(mp[s[end]-
'
A
'
]>=
0
) counter--;
while
(counter==
0
){
if
(end-start+
1
<minLength){
minStart = start;
minLength = end-start+
1
;
}
mp[s[start]-
'
A
'
]++;
if
(mp[s[start]-
'
A
'
]>
0
) counter++;
start++;
}
}
return
minLength==
INT_MAX
?
"
"
: s.
substr
(minStart, minLength);
}
};
Back
|
FazBrowse Home
|
New Git URL