|
|
发表于 2020-3-21 18:31:11
|
显示全部楼层
- #不重复个数字母
- def fun320(str):
- dic = {}
- for each in str:
- dic[each] = str.count(each)
- value_lst = []
- for value in dic.values():
- value_lst.append(value)
- l = len(value_lst)
- value_lst.sort(reverse = True)
- count = 0
- #print(value_lst)
- for i in range(l):
- if i < l-1:
- if value_lst[i] <= value_lst[i+1] and value_lst[i] >= 1:
- count += value_lst[i+1]-value_lst[i]+1
- value_lst[i+1] = value_lst[i] - 1
- if value_lst[i] == 0:
- count +=value_lst[i+1]
- value_lst[i+1] = 0
- return count
复制代码 |
|