当前位置:网站首页>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 ' ';
}
};边栏推荐
- C language to implement a password manager (under update)
- Global and Chinese markets for infrared solutions (for industrial, civil, national defense and security applications) 2022-2028: Research Report on technology, participants, trends, market size and sh
- Address book sorting
- Zzuli:1054 monkeys eat peaches
- Tencent internship interview sorting
- Open under vs2019 UI file QT designer flash back problem
- mmdetection 学习率与batch_size关系
- Yolov5 series (I) -- network visualization tool netron
- Analysis of gene family characteristics - chromosome location analysis
- 什么是Label encoding?one-hot encoding ,label encoding两种编码该如何区分和使用?
猜你喜欢

【Transform】【NLP】首次提出Transformer,Google Brain团队2017年论文《Attention is all you need》
![[ue4] material and shader permutation](/img/8f/7743ac378490fcd7b9ecc5b4c2ef2a.jpg)
[ue4] material and shader permutation

5.4-5.5

Zero copy underlying analysis

远程服务器后台挂起 nohup

dllexport和dllimport
![[graphics] efficient target deformation animation based on OpenGL es 3.0](/img/53/852ac569c930bc419846ac209c8d47.jpg)
[graphics] efficient target deformation animation based on OpenGL es 3.0
![[ue4] Niagara's indirect draw](/img/8a/576022b5d19e1d6422ff0135c50c93.jpg)
[ue4] Niagara's indirect draw

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

Qt development - scrolling digital selector commonly used in embedded system
随机推荐
C language DUP function
Implement Gobang with C language
dllexport和dllimport
【Transform】【实践】使用Pytorch的torch.nn.MultiheadAttention来实现self-attention
5-1 blocking / non blocking, synchronous / asynchronous
[ue4] Niagara's indirect draw
5.4-5.5
[opengl] advanced chapter of texture - principle of flowmap
Write a 2-minute countdown.
Tensor 省略号(三个点)切片
Rasterization: a practical implementation (2)
Yolov5 series (I) -- network visualization tool netron
Use of form text box (I) select text
Open under vs2019 UI file QT designer flash back problem
Zzuli:1042 sum of sequence 3
Composite type (custom type)
The latest M1 dedicated Au update Adobe audit CC 2021 Chinese direct installation version has solved the problems of M1 installation without flash back!
Série yolov5 (i) - - netron, un outil de visualisation de réseau
TPS61170QDRVRQ1
Yolov5 advanced 8 format conversion between high and low versions