当前位置:网站首页>2. < tag hash table, string> supplement: Sword finger offer 50 The first character DBC that appears only once
2. < tag hash table, string> supplement: Sword finger offer 50 The first character DBC that appears only once
2022-07-05 20:47:00 【Caicai's big data development path】
The finger of the sword Offer 50. The first character that appears only once
[ Case needs ]
[ Train of thought analysis 1 , Two traversal ]
[ Code implementation ]
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 ' ';
}
}
[ Train of thought analysis II , utilize 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 ' ';
}
}
边栏推荐
- How to open an account online for futures? Is it safe?
- Abnova cyclosporin a monoclonal antibody and its research tools
- Duchefa low melting point agarose PPC Chinese and English instructions
- Propping of resources
- Implementation of redis unique ID generator
- [Yugong series] go teaching course in July 2022 004 go code Notes
- CADD course learning (7) -- Simulation of target and small molecule interaction (semi flexible docking autodock)
- 资源道具化
- Nprogress plug-in progress bar
- 2.8 basic knowledge of project management process
猜你喜欢
Typhoon is coming! How to prevent typhoons on construction sites!
解析五育融合之下的steam教育模式
Abnova丨DNA 标记高质量控制测试方案
PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
Duchefa MS medium contains vitamin instructions
Graph embedding learning notes
重上吹麻滩——段芝堂创始人翟立冬游记
CADD course learning (7) -- Simulation of target and small molecule interaction (semi flexible docking autodock)
Applet page navigation
How to make ERP inventory accounts of chemical enterprises more accurate
随机推荐
Abnova CD81 monoclonal antibody related parameters and Applications
Redis唯一ID生成器的实现
挖财商学院给的证券账户安全吗?可以开户吗?
National Eye Care Education Conference, 2022 the Fourth Beijing International Youth eye health industry exhibition
AI 从代码中自动生成注释文档
Popular science | does poor English affect the NPDP exam?
鸿蒙系统控制LED的实现方法之经典
Classic implementation method of Hongmeng system controlling LED
19 mongoose modularization
Hongmeng OS' fourth learning
[record of question brushing] 1 Sum of two numbers
[UE4] unrealinsight obtains the real machine performance test report
Maker education infiltrating the transformation of maker spirit and culture
Composition of applet code
解读协作型机器人的日常应用功能
小程序全局配置
Analyze the knowledge transfer and sharing spirit of maker Education
Is it safe to open an account online? Where can I get a low commission?
资源道具化
Common view container class components