题解 | #删除字符串中出现次数最少的字符# 哈希表
删除字符串中出现次数最少的字符
http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
# hashmap解法:分组计数,排除掉最小值的字母
# 时间:单次循环O(n).空间:k个哈希表字符,l个字符存在res,所以O(k+l)
while True:
try:
str1=input()
hashmap,res={},""
for i in str1:
if i not in hashmap:
hashmap[i]=1
else:
hashmap[i]+=1
min_value=min(hashmap.values())
for i in str1:
if hashmap[i] != min_value:
res+=i
print(res)
except:
break
华为机试(python3) 文章被收录于专栏
少壮不努力,老大勤刷题