FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/minimum-window-substring.py at master · tehsints/LeetCode-Solutions · GitHub
tehsints
/
LeetCode-Solutions
Public
forked from
kamyu104/LeetCode-Solutions
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
Python
/
minimum-window-substring.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (30 loc) · 1.2 KB
Breadcrumbs
LeetCode-Solutions
/
Python
/
minimum-window-substring.py
Copy path
File metadata and controls
39 lines (30 loc) · 1.2 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
# Time: O(n)
# Space: O(k), k is the number of different characters
class
Solution
(
object
):
def
minWindow
(
self
,
s
,
t
):
"""
:type s: str
:type t: str
:rtype: str
"""
current_count
=
[
0
for
i
in
xrange
(
52
)]
expected_count
=
[
0
for
i
in
xrange
(
52
)]
for
char
in
t
:
expected_count
[
ord
(
char
)
-
ord
(
'a'
)]
+=
1
i
,
count
,
start
,
min_width
,
min_start
=
0
,
0
,
0
,
float
(
"inf"
),
0
while
i
<
len
(
s
):
current_count
[
ord
(
s
[
i
])
-
ord
(
'a'
)]
+=
1
if
current_count
[
ord
(
s
[
i
])
-
ord
(
'a'
)]
<=
expected_count
[
ord
(
s
[
i
])
-
ord
(
'a'
)]:
count
+=
1
if
count
==
len
(
t
):
while
expected_count
[
ord
(
s
[
start
])
-
ord
(
'a'
)]
==
0
or
\
current_count
[
ord
(
s
[
start
])
-
ord
(
'a'
)]
>
expected_count
[
ord
(
s
[
start
])
-
ord
(
'a'
)]:
current_count
[
ord
(
s
[
start
])
-
ord
(
'a'
)]
-=
1
start
+=
1
if
min_width
>
i
-
start
+
1
:
min_width
=
i
-
start
+
1
min_start
=
start
i
+=
1
if
min_width
==
float
(
"inf"
):
return
""
return
s
[
min_start
:
min_start
+
min_width
]
Back
|
FazBrowse Home
|
New Git URL