当前位置:网站首页>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 ' ';
}
}
边栏推荐
- 物联网智能家居基本方法实现之经典
- 2022北京眼睛健康用品展,护眼产品展,中国眼博会11月举办
- Duchefa丨S0188盐酸大观霉素五水合物中英文说明书
- mongodb/文档操作
- Informatics Olympiad 1338: [example 3-3] hospital setting | Luogu p1364 hospital setting
- Monorepo管理方法论和依赖安全
- 小程序页面导航
- Duchefa丨D5124 MD5A 培养基中英文说明书
- Informatics Olympiad 1337: [example 3-2] word search tree | Luogu p5755 [noi2000] word search tree
- [UE4] unrealinsight obtains the real machine performance test report
猜你喜欢
王老吉药业“关爱烈日下最可爱的人”公益活动在南京启动
Abnova丨培养细胞总 RNA 纯化试剂盒中英文说明书
Abnova丨 MaxPab 小鼠源多克隆抗体解决方案
Specification of protein quantitative kit for abbkine BCA method
Classic implementation of the basic method of intelligent home of Internet of things
Abnova e (diii) (WNV) recombinant protein Chinese and English instructions
Ros2 topic [01]: installing ros2 on win10
Duchefa细胞分裂素丨二氢玉米素 (DHZ)说明书
Analysis of steam education mode under the integration of five Education
Informatics Orsay all in one 1339: [example 3-4] find the post order traversal | Valley p1827 [usaco3.4] American Heritage
随机推荐
CCPC 2021 Weihai - G. shinyruo and KFC (combination number, tips)
Abnova丨 CD81单克隆抗体相关参数和应用
Abnova丨E (DIII) (WNV) 重组蛋白 中英文说明书
matplotlib绘图润色(如何形成高质量的图,例如设如何置字体等)
How to renew NPDP? Here comes the operation guide!
Which securities is better for securities account opening? Is online account opening safe?
Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms
Monorepo管理方法论和依赖安全
Duchefa s0188 Chinese and English instructions of spectinomycin hydrochloride pentahydrate
Duchefa丨低熔点琼脂糖 PPC中英文说明书
如何形成规范的接口文档
Schema and model
Kubernetes resource object introduction and common commands (V) - (configmap & Secret)
Abnova fluorescent dye 620-m streptavidin scheme
MySQL fully parses json/ arrays
Leetcode (695) - the largest area of an island
Practical demonstration: how can the production research team efficiently build the requirements workflow?
Abnova丨培养细胞总 RNA 纯化试剂盒中英文说明书
CTF逆向基础
AI automatically generates annotation documents from code