当前位置:网站首页>[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
}
}
边栏推荐
- 全面掌握const的用法《一》
- Zadig + cave Iast: let safety dissolve in continuous delivery
- On the necessity and solution of building a campus online teaching video convergence platform
- 小样本利器2.文本对抗+半监督 FGSM & VAT & FGM代码实现
- After crossing, she said that the multiverse really exists
- code review
- 以产业互联网的发展为开端,行业才能进入到一个全新的发展阶段
- CS5463代码模块解析(包含下载链接)
- 网上办理股票开户安全性高吗?
- Code example of hiredis
猜你喜欢

2022-06-28: what does the following golang code output? A:true; B:false; C:panic; D: Compilation failed. package main import “fmt“ func main() {

一文读懂,WMS仓储管理系统与ERP有什么区别

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

Windows mysql5.7 enable binlog log
![LeetCode 324 摆动排序 II[排序 双指针] HERODING的LeetCode之路](/img/41/b8ba8d771b7224eac1cc8c54fe9d29.png)
LeetCode 324 摆动排序 II[排序 双指针] HERODING的LeetCode之路

论文解读(DCN)《Towards K-means-friendly Spaces: Simultaneous Deep Learning and Clustering》

How to use London gold to draw support resistance line

生产环境sonarqube安装

Summary of time series prediction series (code usage)

QtCreator5.15.0源码编译全过程记录
随机推荐
The Best of Many Worlds_ Dual Mirror Descent for Online Allocation Problems
Zadig + 洞态 IAST:让安全溶于持续交付
Google Earth engine (GEE) -- crop extraction and analysis using sentinel-2 data
[kotlin] beautiful pop-up box, custom pop-up box (dialog box), extension function, chrysanthemum waiting bar, message prompt box
在QT进行cin(全网最清晰教程)
Multiomics single cell data integration and regulatory reasoning based on graph linked embedding
邂逅阿维塔 11:强产品力下久违的新鲜感
【深度学习】(3) Transformer 中的 Encoder 机制,附Pytorch完整代码
TCP three handshakes and four waves
Undefined symbol main (referred from entry9a.o).
复杂嵌套的对象池(4)——管理多类实例和多阶段实例的对象池
torch. nn. Transformer import failed
【剑指Offer】50. 第一个只出现一次的字符
Mysql通过ibd文件恢复数据的详细步骤
国盛证券开户是真的安全可靠吗
Career consultation | in the data analysis interview, it is only reliable to introduce yourself in this way
Prometeus 2.36.0 新特性
Deep virtual memory (VM)
【SSH】无密码登录
Mono's execution process