FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/string-compression.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
/
string-compression.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (26 loc) · 880 Bytes
Breadcrumbs
LeetCode-Solutions
/
Python
/
string-compression.py
Copy path
File metadata and controls
28 lines (26 loc) · 880 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
20
21
22
23
24
25
26
27
# Time: O(n)
# Space: O(1)
class
Solution
(
object
):
def
compress
(
self
,
chars
):
"""
:type chars: List[str]
:rtype: int
"""
anchor
,
write
=
0
,
0
for
read
,
c
in
enumerate
(
chars
):
if
read
+
1
==
len
(
chars
)
or
chars
[
read
+
1
]
!=
c
:
chars
[
write
]
=
chars
[
anchor
]
write
+=
1
if
read
>
anchor
:
n
,
left
=
read
-
anchor
+
1
,
write
while
n
>
0
:
chars
[
write
]
=
chr
(
n
%
10
+
ord
(
'0'
))
write
+=
1
n
/=
10
right
=
write
-
1
while
left
<
right
:
chars
[
left
],
chars
[
right
]
=
chars
[
right
],
chars
[
left
]
left
+=
1
right
-=
1
anchor
=
read
+
1
return
write
Back
|
FazBrowse Home
|
New Git URL