当前位置:网站首页>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 ' ';
}
}
边栏推荐
- Graph embedding learning notes
- Informatics Olympiad 1338: [example 3-3] hospital setting | Luogu p1364 hospital setting
- Model method
- 当Steam教育进入个性化信息技术课程
- Is it safe to open an account online? Where can I get a low commission?
- Wanglaoji pharmaceutical's public welfare activity of "caring for the most lovely people under the scorching sun" was launched in Nanjing
- Abnova CRISPR spcas9 polyclonal antibody protocol
- phpstudy小皮的mysql点击启动后迅速闪退,已解决
- 1. Strengthen learning basic knowledge points
- Hongmeng OS' fourth learning
猜你喜欢

Abnova丨培养细胞总 RNA 纯化试剂盒中英文说明书

表单文本框的使用(二) 输入过滤(合成事件)

CVPR 2022 | common 3D damage and data enhancement

解析创客教育的知识迁移和分享精神

Kubernetes resource object introduction and common commands (V) - (configmap & Secret)

Duchefa丨低熔点琼脂糖 PPC中英文说明书

小程序全局配置

PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug

Abnova丨CRISPR SpCas9 多克隆抗体方案

CADD course learning (7) -- Simulation of target and small molecule interaction (semi flexible docking autodock)
随机推荐
Schema and model
Analysis of steam education mode under the integration of five Education
手机开户股票开户安全吗?我家比较偏远,有更好的开户途径么?
Duchefa丨低熔点琼脂糖 PPC中英文说明书
欢迎来战,赢取丰厚奖金:Code Golf 代码高尔夫挑战赛正式启动
Typhoon is coming! How to prevent typhoons on construction sites!
[quick start of Digital IC Verification] 2. Through an example of SOC project, understand the architecture of SOC and explore the design process of digital system
Applet project structure
Use of form text box (II) input filtering (synthetic event)
Leetcode (695) - the largest area of an island
资源道具化
Abnova blood total nucleic acid purification kit pre installed relevant instructions
Is it safe to open an account online? Where can I get a low commission?
19 mongoose modularization
鸿蒙系统控制LED的实现方法之经典
AI 从代码中自动生成注释文档
[Yugong series] go teaching course in July 2022 004 go code Notes
Duchefa cytokinin dihydrozeatin (DHZ) instructions
【UE4】UnrealInsight获取真机性能测试报告
Abnova 环孢素A单克隆抗体,及其研究工具