FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/distant-barcodes.py at master · pythonpeixun/LeetCode-Solutions · GitHub
pythonpeixun
/
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
/
distant-barcodes.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
24 lines (20 loc) · 611 Bytes
Breadcrumbs
LeetCode-Solutions
/
Python
/
distant-barcodes.py
Copy path
File metadata and controls
24 lines (20 loc) · 611 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
# Time: O(klogk), k is the number of distinct barcodes
# Space: O(k)
import
collections
class
Solution
(
object
):
def
rearrangeBarcodes
(
self
,
barcodes
):
"""
:type barcodes: List[int]
:rtype: List[int]
"""
cnts
=
collections
.
Counter
(
barcodes
)
sorted_cnts
=
[[
v
,
k
]
for
k
,
v
in
cnts
.
iteritems
()]
sorted_cnts
.
sort
(
reverse
=
True
)
i
=
0
for
v
,
k
in
sorted_cnts
:
for
_
in
xrange
(
v
):
barcodes
[
i
]
=
k
i
+=
2
if
i
>=
len
(
barcodes
):
i
=
1
return
barcodes
Back
|
FazBrowse Home
|
New Git URL