当前位置:网站首页>2.<tag-哈希表, 字符串>补充: 剑指 Offer 50. 第一个只出现一次的字符 dbc
2.<tag-哈希表, 字符串>补充: 剑指 Offer 50. 第一个只出现一次的字符 dbc
2022-07-05 20:40:00 【菜菜的大数据开发之路】
剑指 Offer 50. 第一个只出现一次的字符
[案例需求]

[思路分析一, 两次遍历]

[代码实现]
class Solution {
public char firstUniqChar(String s) {
Map<Character, Integer> frequency = new HashMap<Character, Integer>();
for (int i = 0; i < s.length(); ++i) {
char ch = s.charAt(i);
frequency.put(ch, frequency.getOrDefault(ch, 0) + 1);
}
for (int i = 0; i < s.length(); ++i) {
if (frequency.get(s.charAt(i)) == 1) {
return s.charAt(i);
}
}
return ' ';
}
}

[思路分析二, 利用API]
class Solution {
public char firstUniqChar(String s) {
for(int i = 0; i< s.length(); i++){
char value = s.charAt(i);
if(s.indexOf(value)==s.lastIndexOf(value)){
return value;
}
}
return ' ';
}
}
边栏推荐
- 挖财商学院给的证券账户安全吗?可以开户吗?
- 14、Transformer--VIT TNT BETR
- Classic implementation method of Hongmeng system controlling LED
- Document method
- CVPR 2022 | common 3D damage and data enhancement
- 19 mongoose modularization
- Model method
- 【愚公系列】2022年7月 Go教学课程 004-Go代码注释
- Is it safe to open a stock account by mobile phone? My home is relatively remote. Is there a better way to open an account?
- Abbkine丨TraKine F-actin染色试剂盒(绿色荧光)方案
猜你喜欢

Specification of protein quantitative kit for abbkine BCA method

Leetcode (695) - the largest area of an island

CADD course learning (7) -- Simulation of target and small molecule interaction (semi flexible docking autodock)

Abnova DNA marker high quality control test program

Applet page navigation

Abbkine trakine F-actin Staining Kit (green fluorescence) scheme

Duchefa丨S0188盐酸大观霉素五水合物中英文说明书

How to form standard interface documents

如何让化工企业的ERP库存账目更准确
![[Yugong series] go teaching course in July 2022 004 go code Notes](/img/18/ffbab0a251dc2b78eb09ce281c2703.png)
[Yugong series] go teaching course in July 2022 004 go code Notes
随机推荐
Enter the parallel world
小程序项目结构
Abnova丨荧光染料 620-M 链霉亲和素方案
How to make ERP inventory accounts of chemical enterprises more accurate
资源道具化
[Yugong series] go teaching course in July 2022 004 go code Notes
小程序页面导航
手机开户股票开户安全吗?我家比较偏远,有更好的开户途径么?
Mysql频繁操作出现锁表问题
Abnova丨血液总核酸纯化试剂盒预装相关说明书
matplotlib绘图润色(如何形成高质量的图,例如设如何置字体等)
Abbkine BCA法 蛋白质定量试剂盒说明书
ProSci LAG-3 重组蛋白说明书
Abnova maxpab mouse derived polyclonal antibody solution
重上吹麻滩——段芝堂创始人翟立冬游记
Duchefa p1001 plant agar Chinese and English instructions
Informatics Olympiad 1337: [example 3-2] word search tree | Luogu p5755 [noi2000] word search tree
【刷题记录】1. 两数之和
NPDP如何续证?操作指南来了!
phpstudy小皮的mysql点击启动后迅速闪退,已解决