FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/special-binary-string.py at master · Monika-R/LeetCode-Solutions · GitHub
Monika-R
/
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
/
special-binary-string.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
20 lines (18 loc) · 628 Bytes
Breadcrumbs
LeetCode-Solutions
/
Python
/
special-binary-string.py
Copy path
File metadata and controls
20 lines (18 loc) · 628 Bytes
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
# Time: f(n) = k * f(n/k) + n/k * klogk <= O(logn * nlogk) <= O(n^2)
# n is the length of S, k is the max number of special strings in each depth
# Space: O(n)
class
Solution
(
object
):
def
makeLargestSpecial
(
self
,
S
):
"""
:type S: str
:rtype: str
"""
result
=
[]
anchor
=
count
=
0
for
i
,
v
in
enumerate
(
S
):
count
+=
1
if
v
==
'1'
else
-
1
if
count
==
0
:
result
.
append
(
"1{}0"
.
format
(
self
.
makeLargestSpecial
(
S
[
anchor
+
1
:
i
])))
anchor
=
i
+
1
result
.
sort
(
reverse
=
True
)
return
""
.
join
(
result
)
Back
|
FazBrowse Home
|
New Git URL