squirrel2300

导航

Pythonic

arr = [char for char, count in Counter(S).most_common() for _ in range(count)]
alen = len(arr)
half_len = (alen >> 1) + 1 if alen&1  else (alen >> 1)
res = [0] * alen
res[::2], res[1::2] = arr[:half_len], arr[half_len:]

 

chars = [char for char, count in Counter(S).most_common() for _ in range(count)]
h = math.ceil(len(chars) / 2)
chars[::2], chars[1::2] = chars[:h], chars[h:]

 

posted on 2018-05-17 10:48  squirrel2300  阅读(116)  评论(0编辑  收藏  举报