当前位置:网站首页>[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
}
}
边栏推荐
- Water brother's code
- [gateway development] handle the IP address segment represented by CIDR when NGX nested Lua
- A password error occurred when docker downloaded the MySQL image to create a database link
- Pytorch builds transformer to realize multivariable and multi step time series forecasting (load forecasting)
- Set when quartz scheduled task trigger starts
- 手机办理股票开户安全性高吗?
- Is it safe to open a stock account by mobile phone?
- 长投学堂帮忙开证券账户是安全靠谱的吗?个人如何开
- 云计算的迷路者
- Deep virtual memory (VM)
猜你喜欢

Leetcode detailed explanation of stack type

2022-06-28:以下golang代码输出什么?A:true;B:false;C:panic;D:编译失败。 package main import “fmt“ func main() {

Basic knowledge diagram of K-line Diagram -- meaning of single K-line

Panxiaoming, senior vice president of IC nansha|amd and President of Greater China: process, architecture and platform optimization break through the computing boundary

Deep virtual memory (VM)

Get to know Alibaba cloud (Cloud Computing) - development history, technical architecture, region and availability zone!

超级工厂里的生意图鉴

微搭低代码中实现二维码生成

Wave picking of WMS warehouse management system module

Realization of 2D code generation in micro build low code
随机推荐
oracle设置密码复杂度及设置超时退出的功能
Huawei cloud gaussdb (for redis) unveiling issue 19: inventory of six second level capabilities
网上办理股票开户安全性高吗?
Implementation of go language plug-in platform
Water brother's code
Production environment sonarqube installation
QtCreator5.15.0源码编译全过程记录
Sample code of using redis to realize the like function
code review
Code example of hiredis
LeCun预言AGI:大模型和强化学习都是斜道!我的世界模型才是新路
Qsrand, srand random number generating function in qt5.15 has been discarded
Online text filter less than specified length tool
Explanation: Luogu p1762 even number /6.21 internal examination T2
Realization of 2D code generation in micro build low code
在产业互联网时代,传统意义上的互联网将会演变出来诸多新的形态
Embedded dynamic Arabic string conversion LCD display string [thanks for Jianguo ambition]
With the development of industrial Internet as the starting point, the industry can enter a new stage of development
Can we still enter the "pit" data analysis now? Look at the hot jobs of data analysis in 2022!
CPU、GPU、TPU、NPU区别