当前位置:网站首页>[sword finger offer] 50 First character that appears only once
[sword finger offer] 50 First character that appears only once
2022-06-28 22:56:00 【LuZhouShiLi】
The finger of the sword Offer 50. The first character that appears only once
subject
In string s Find the first character that appears only once . without , Return a single space . s Contains only lowercase letters .
Ideas
Create a new hash table , Store... As a key value pair , value - The number of occurrences of each character ( Boolean type ), Finally, the loop returns the first character that appears only once .
Code
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));// If it is not in the Kazakhstan table Add it directly
}
for(char c:sc)
{
if(dic.get(c))
{
return c;// Get the first occurrence of the character
}
}
return ' ';// If not, return a space
}
}
边栏推荐
- With the development of industrial Internet as the starting point, the industry can enter a new stage of development
- keil工程,程序写多后,RTT不能打印
- Implementation of go language plug-in platform
- 嵌入式中 动态阿拉伯语字符串 转换 LCD显示字符串【感谢建国雄心】
- Database basic notes
- WMS仓库管理系统模块之波次拣货
- 超级工厂里的生意图鉴
- TCP three handshakes and four waves
- Explanation: Luogu p1762 even number /6.21 internal examination T2
- 浅析搭建校园在线教学视频汇聚平台的必要性及解决方案
猜你喜欢

WEB API学习笔记1

Zadig + 洞态 IAST:让安全溶于持续交付

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

This simple little function saves 213 hours for our production research team in half a year

After crossing, she said that the multiverse really exists

深入虚拟内存(Virtual Memory,VM)

CS5463代码模块解析(包含下载链接)

Detailed explanation of Zadig's self-test and joint debugging sub environment for developers

Summary of time series prediction series (code usage)

The new version of OpenAPI engine of Kingdee cloud dome is coming!
随机推荐
台式机没声音怎么样才能解决
Online linear programming: Dual convergence, new algorithms, and regret bounds
Prometeus 2.36.0 新特性
稳!上千微服务如何快速接入 Zadig(Helm Chart 篇)
强大的开源API接口可视化管理平台-YApi
手机办理股票开户安全性高吗?
PyTorch搭建Transformer实现多变量多步长时间序列预测(负荷预测)
【SSH】无密码登录
如何使用伦敦金画出支撑阻力线
【kotlin】好看的弹出框、自定义弹出框(对话框)、扩展函数、菊花等待条、消息提示框
Summary of time series prediction series (code usage)
TCP three handshakes and four waves
Can we still enter the "pit" data analysis now? Look at the hot jobs of data analysis in 2022!
浅析搭建校园在线教学视频汇聚平台的必要性及解决方案
论文解读(DCN)《Towards K-means-friendly Spaces: Simultaneous Deep Learning and Clustering》
Oracle set password complexity and timeout exit function
Redis+AOP+自定义注解实现限流
计数排序的简单理解
How to solve the problem of desktop without sound
Ansible production environment usage scenario (7): batch deployment of elk clients