当前位置:网站首页>【剑指Offer】50. 第一个只出现一次的字符
【剑指Offer】50. 第一个只出现一次的字符
2022-06-28 22:45:00 【LuZhouShiLi】
剑指 Offer 50. 第一个只出现一次的字符
题目
在字符串 s 中找出第一个只出现一次的字符。如果没有,返回一个单空格。 s 只包含小写字母。
思路
新建一个哈希表,以键值对形式存储,值-每一个字符出现的次数(布尔类型),最后循环返回第一个只出现一次的字符。
代码
class Solution {
public char firstUniqChar(String s) {
HashMap<Character,Boolean> dic = new HashMap<>();
char[] sc = s.toCharArray();
for(char c : sc)
{
dic.put(c,!dic.containsKey(c));// 如果不在哈系表中 直接添加进去
}
for(char c:sc)
{
if(dic.get(c))
{
return c;// 获取第一次出现的字符
}
}
return ' ';// 没有的话返回空格
}
}
边栏推荐
- Qt5.15中qsrand,srand随机数生成函数已弃用问题
- 如何结合均线分析伦敦金行情走势线图
- A password error occurred when docker downloaded the MySQL image to create a database link
- 超级工厂里的生意图鉴
- How to solve the problem of desktop without sound
- torch. nn. Transformer import failed
- Online linear programming: Dual convergence, new algorithms, and regret bounds
- 以产业互联网的发展为开端,行业才能进入到一个全新的发展阶段
- Simple understanding of counting and sorting
- Panxiaoming, senior vice president of IC nansha|amd and President of Greater China: process, architecture and platform optimization break through the computing boundary
猜你喜欢

在线文本过滤小于指定长度工具

FANUC机器人_KAREL编程入门(2)_通用IO信号的使用方法

生产环境sonarqube安装

强大的开源API接口可视化管理平台-YApi

如何使用伦敦金画出支撑阻力线

Jointly explore digital technology and information security, and the fourth China Russia Digital Forum was successfully held

QtCreator5.15.0源码编译全过程记录

Pytorch builds transformer to realize multivariable and multi step time series forecasting (load forecasting)

After crossing, she said that the multiverse really exists

Zadig + cave Iast: let safety dissolve in continuous delivery
随机推荐
如何使用伦敦金画出支撑阻力线
Set when quartz scheduled task trigger starts
Wechat red envelope cover making tutorial and use guide with link jump
CPU、GPU、TPU、NPU区别
After crossing, she said that the multiverse really exists
Progress of dbnn experiment
Career consultation | in the data analysis interview, it is only reliable to introduce yourself in this way
torch. nn. Transformer import failed
爱数SMART 2022峰会开启,分享数据战略与建设数据驱动型组织方法论
浅析搭建校园在线教学视频汇聚平台的必要性及解决方案
时间序列预测系列文章总结(代码使用方法)
论文解读(DCN)《Towards K-means-friendly Spaces: Simultaneous Deep Learning and Clustering》
Oracle deleting archived logs and adding scheduled tasks
在线SQL转HTMLTable工具
C#/VB. Net to convert PDF to excel
穿越过后,她说多元宇宙真的存在
Get to know Alibaba cloud (Cloud Computing) - development history, technical architecture, region and availability zone!
复杂嵌套的对象池(4)——管理多类实例和多阶段实例的对象池
SqlServer复习
windows mysql5.7 开启binlog日志