题目描述:
- 给定一个乱序的数组,删除所有的重复元素,使得每个元素只出现一次,并且按照出现的次数从高到低进行排序,相同出现次数按照第一次出现顺序进行先后排序。
输入描述:
一个数组
输出描述:
去重排序后的数组
补充说明:
数组大小不超过100
数组元素值大小不超过100
示例1
输入:
1,3,3,3,2,4,4,4,5输出:
3,4,1,2,5说明:
import sys
def rm_dup_reorder(arr: List[int]):
d = {}
for n in arr:
if n not in d.keys():
d[n] = 1
else:
d[n] +=1
d_ = {}
for key, value in d.items():
if value not in d_.keys():
d_[value] = [key]
else:
d_[value].append(key)
result = []
for n in sorted(d_.keys(), reverse=True):
result += d_[n]
return result
for line in sys.stdin.readlines():
array = [int(x) for x in line.split(",")]
print(",".join([str(x) for x in rm_dup_reorder(array)]))