当前位置:网站首页>[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
}
}
边栏推荐
- Differences among CPU, GPU, TPU and NPU
- 2022-06-28:以下golang代码输出什么?A:true;B:false;C:panic;D:编译失败。 package main import “fmt“ func main() {
- Online linear programming: Dual convergence, new algorithms, and regret bounds
- The new version of OpenAPI engine of Kingdee cloud dome is coming!
- 生产环境sonarqube安装
- 华为云GaussDB(for Redis)揭秘第19期:六大秒级能力盘点
- In the era of industrial Internet, the Internet in the traditional sense will evolve into many new forms
- Is it safe and reliable for changtou school to help open a securities account? How to drive
- Career consultation | how to answer the question of career planning during the interview?
- CPU、GPU、TPU、NPU区别
猜你喜欢

Business atlas in super factory

What is low code development?
利用Redis实现点赞功能的示例代码

Summary of time series prediction series (code usage)

After crossing, she said that the multiverse really exists

On the necessity and solution of building a campus online teaching video convergence platform

全面掌握const的用法《一》

Zadig + cave Iast: let safety dissolve in continuous delivery

在QT进行cin(全网最清晰教程)

What is the difference between WMS warehouse management system and ERP
随机推荐
论文解读(DCN)《Towards K-means-friendly Spaces: Simultaneous Deep Learning and Clustering》
台式机没声音怎么样才能解决
hiredis的代码示例
【剑指Offer】50. 第一个只出现一次的字符
【Try to Hack】nmap
Ingénieur natif du nuage après 00: utiliser Zadig pour développer des sources ouvertes et des économies d'énergie pour la technologie innovante (bus de Guangzhou)
一文读懂,WMS仓储管理系统与ERP有什么区别
全面掌握const的用法《一》
Mysql通过ibd文件恢复数据的详细步骤
论文解读(DCN)《Towards K-means-friendly Spaces: Simultaneous Deep Learning and Clustering》
Detailed steps for MySQL to recover data through IBD files
Code example of hiredis
After crossing, she said that the multiverse really exists
【kotlin】好看的弹出框、自定义弹出框(对话框)、扩展函数、菊花等待条、消息提示框
leetCode-栈类型详解
The new version of OpenAPI engine of Kingdee cloud dome is coming!
[deep learning] (3) encoder mechanism in transformer, complete pytoch code attached
Deep virtual memory (VM)
直击产业落地 | 飞桨重磅推出业界首个模型选型工具
[kotlin] beautiful pop-up box, custom pop-up box (dialog box), extension function, chrysanthemum waiting bar, message prompt box