当前位置:网站首页>HJ删除字符串中出现次数最少的字符
HJ删除字符串中出现次数最少的字符
2022-06-28 07:36:00 【有勇气的牛排】
知识点:字符串、哈希
描述
实现删除字符串中出现次数最少的字符,若出现次数最少的字符有多个,则把出现次数最少的字符都删除。输出删除这些单词后的字符串,字符串中其它字符保持原来的顺序。
数据范围:输入的字符串长度满足1≤n≤20,保证输入的字符串中仅出现小写字母
输入描述:
字符串只包含小写英文字母, 不考虑非法输入,输入的字符串长度小于等于20个字节。
输出描述:
删除字符串中出现次数最少的字符后的字符串。
示例1
输入:aabcddd
输出:aaddd
牛客 HJ Python
# 运行时间29ms 占用内存4532KB
while True:
try:
# 输入
str = input()
dic, res = {
}, ""
# 每个字母录入字典
for i in str:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
# 获取字典中 值最小的
min = min(dic.values())
# 将最小值 替换为空
for i in str:
if dic[i] == min:
str = str.replace(i, "")
print(str)
except:
break
边栏推荐
- kubelet垃圾(退出的容器和未使用的镜像)回收源码分析
- 什么是EC鼓风机(ec blower fan)?
- What should I do if the version is incompatible with the jar package conflict?
- 8 figures | analyze Eureka's first synchronization registry
- 在idea中,get和set方法爆红可能是没有安装Lombok插件
- Llvm and clang
- MySQL master-slave replication, detailed configuration, create unable to connect processing prompt
- Open62541 import nodeset file directly
- linux下修改mysql用户名root
- pip 更新到最新的版本
猜你喜欢

ABAP skill tree

kubernetes删除pod的流程的源码简析

Alibaba cloud server creates snapshots and rolls back disks

Jinshan cloud team shared | 5000 words to understand how Presto matches with alluxio

ABAP 技能树

HTTP Caching Protocol practice

A gadget can write crawlers faster

PLC -- Notes

Application and Optimization Practice of redis in vivo push platform

Source code analysis of kubernetes' process of deleting pod
随机推荐
Alibaba cloud server creates snapshots and rolls back disks
Makefile
MySQL master-slave replication, detailed configuration, create unable to connect processing prompt
7-2 芬兰木棋 结构体排序
kubernetes部署thanos ruler的发送重复告警的一个隐秘的坑
R and RGL draw 3D knots
Source code analysis of kubernetes' process of deleting pod
实时数据库 - 笔记
Self discipline challenge 30 days
扩展Prometheus的解决方案thanos的简介和几个月使用心得
Yesterday, I went to a large factory for an interview and asked me to do four arithmetic operations. Fortunately, I am smart enough
[thanos source code analysis series]thanos query component source code analysis
打新债注册开户靠谱吗?安全吗?
基金的投资交易与结算
MySQL installation steps - installing MySQL on Linux (3)
GoLand IDE and delve debug Go programs in kubernetes cluster
In idea, the get and set methods may be popular because the Lombok plug-in is not installed
ice - 资源
Top 25 most popular articles on vivo Internet technology in 2021
Analyze 5 indicators of NFT project