当前位置:网站首页>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
边栏推荐
- 打新债注册开户靠谱吗?安全吗?
- 异或的应用。(提取出数字中最右侧的1,面试中经常用的到)
- flutter 实现摇一摇功能
- Recommended system series (Lecture 5): Optimization Practice of sorting model
- In idea, the get and set methods may be popular because the Lombok plug-in is not installed
- Unity-UI-shadow组件
- MySQL installation steps - Linux configuration file JDK installation (II)
- Top 25 most popular articles on vivo Internet technology in 2021
- ABAP 技能树
- kubelet垃圾(退出的容器和未使用的镜像)回收源码分析
猜你喜欢

Pfizer's new Guankou medicine has entered the Chinese market, and the listing of relevant products of domestic pharmaceutical enterprises is just around the corner

kubernetes删除pod的流程的源码简析
![[thanos source code analysis series]thanos query component source code analysis](/img/e4/2a87ef0d5cee0cc1c1e1b91b6fd4af.png)
[thanos source code analysis series]thanos query component source code analysis

A single node obtains the lock lock of the order number

扩展Prometheus的解决方案thanos的简介和几个月使用心得

卸载重装最新版mysql数据库亲测有效

Uninstall and reinstall the latest version of MySQL database. The test is valid

Yesterday, I went to a large factory for an interview and asked me to do four arithmetic operations. Fortunately, I am smart enough

Alibaba cloud server creates snapshots and rolls back disks

Mysql57 zip file installation
随机推荐
Practice of traffic recording and playback in vivo
网传互联网公司加班表,排名第一的没悬念
Makefile
同花顺网上开户安全吗
[thanos source code analysis series]thanos query component source code analysis
卸载重装最新版mysql数据库亲测有效
[ thanos源码分析系列 ]thanos query组件源码简析
7-1 懂的都懂
Yesterday, I went to a large factory for an interview and asked me to do four arithmetic operations. Fortunately, I am smart enough
PLC -- 笔记
NDK cross compilation
ACM notes
实时数据库 - 笔记
Kubernetes deploys a secret pit where thanos ruler sends repeated alarms
Reading notes - MySQL technology l act: InnoDB storage engine (version 2)
一个小工具可以更快的写爬虫
MySQL installation steps - Linux configuration file JDK installation (II)
linux下修改mysql用户名root
kubernetes部署thanos ruler的发送重复告警的一个隐秘的坑
A small code editor can also run programs -- a summary of sublime Text3 running programs in various languages