当前位置:网站首页>The first character of leetcode sword offer that only appears once (12)
The first character of leetcode sword offer that only appears once (12)
2022-07-03 14:59:00 【& eternal Galaxy &】
Title Description
character string s Find the first character that appears only once . without , Return a single space . s Contains only lowercase letters .
Example 1:
Input :s = "abaccdeff" Output :'b'
Example 2:
Input :s = "" Output :' '
python3 Realization
Coding ideas : Slicing method (python alone possess ), It can also be used. hash map
class Solution:
def firstUniqChar(self, s: str) -> str:
rs = " "
for i in range(len(s)):
if s[i] not in s[:i] and s[i] not in s[i+1:]:
return s[i]
return rsc++ Realization
Encoding idea : Storage frequency using hash table
class Solution {
public:
char firstUniqChar(string s) {
unordered_map<int, int> freq;
for(char c:s){
++freq[c];
}
for(int i=0; i<s.size();i++){
if(freq[s[i]] == 1)
return s[i];
}
return ' ';
}
};边栏推荐
- Centos7 deployment sentry redis (with architecture diagram, clear and easy to understand)
- 【微信小程序】WXSS 模板样式
- Global and Chinese markets for sterile packaging 2022-2028: Research Report on technology, participants, trends, market size and share
- Analysis of gene family characteristics - chromosome location analysis
- Global and Chinese market of Bus HVAC systems 2022-2028: Research Report on technology, participants, trends, market size and share
- 什么是Label encoding?one-hot encoding ,label encoding两种编码该如何区分和使用?
- NOI OPENJUDGE 1.4(15)
- Tencent internship interview sorting
- 406. 根据身高重建队列
- 【Transform】【实践】使用Pytorch的torch.nn.MultiheadAttention来实现self-attention
猜你喜欢

Solve the problem that PR cannot be installed on win10 system. Pr2021 version -premiere Pro 2021 official Chinese version installation tutorial

4-33--4-35

Qt development - scrolling digital selector commonly used in embedded system

零拷贝底层剖析

Devaxpress: range selection control rangecontrol uses

什么是one-hot encoding?Pytorch中,将label变成one hot编码的两种方式

Dllexport et dllimport
![[graphics] real shading in Unreal Engine 4](/img/8d/53775c7570c5578f4fe985592bb305.jpg)
[graphics] real shading in Unreal Engine 4

My QT learning path -- how qdatetimeedit is empty

C language DUP function
随机推荐
Web server code parsing - thread pool
Composite type (custom type)
Zero copy underlying analysis
Zzuli:1046 product of odd numbers
Pytoch deep learning and target detection practice notes
NOI OPENJUDGE 1.3(06)
Yolov5系列(一)——网络可视化工具netron
Zzuli:1049 square sum and cubic sum
Open under vs2019 UI file QT designer flash back problem
dllexport和dllimport
Pytorch深度学习和目标检测实战笔记
Global and Chinese market of postal automation systems 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese markets for ionization equipment 2022-2028: Research Report on technology, participants, trends, market size and share
Tensor ellipsis (three points) slice
7-9 one way in, two ways out (25 points)
什么是Label encoding?one-hot encoding ,label encoding两种编码该如何区分和使用?
Yolov5进阶之七目标追踪最新环境搭建(二)
NOI OPENJUDGE 1.6(09)
Zzuli:1058 solving inequalities
Detailed explanation of four modes of distributed transaction (Seata)