Skip to content

Commit 737ddca

Browse files
committed
refact: Reorganize String
1 parent 1300483 commit 737ddca

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

Python/0767. Reorganize String.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@
5151
class Solution:
5252
def reorganizeString(self, S: str) -> str:
5353
res = ""
54-
q = []
55-
counter = Counter(S)
56-
for c, count in counter.items():
57-
heapq.heappush(q, (-count, c))
54+
q = [(-count, c) for c, count in Counter(S).items()]
55+
heapq.heapify(q)
5856
pre_count, pre_c = 0, ""
5957
while q:
6058
count, c = heapq.heappop(q)

0 commit comments

Comments
 (0)