当前位置:网站首页>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 rs
c++ 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 ' ';
}
};
边栏推荐
- Zzuli:1055 rabbit reproduction
- Dllexport and dllimport
- [combinatorics] permutation and combination (set combination, one-to-one correspondence model analysis example)
- NOI OPENJUDGE 1.5(23)
- 7-10 stack of hats (25 points) (C language solution)
- How to color ordinary landscape photos, PS tutorial
- [ue4] HISM large scale vegetation rendering solution
- Global and Chinese market of postal automation systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Vs+qt application development, set software icon icon
- Byte practice surface longitude
猜你喜欢
CentOS7部署哨兵Redis(带架构图,清晰易懂)
QT - draw something else
How does vs+qt set the software version copyright, obtain the software version and display the version number?
B2020 分糖果
QT program font becomes larger on computers with different resolutions, overflowing controls
Qt—绘制其他东西
【Transform】【NLP】首次提出Transformer,Google Brain团队2017年论文《Attention is all you need》
4-29——4.32
How to color ordinary landscape photos, PS tutorial
链表有环,快慢指针走3步可以吗
随机推荐
Chapter 14 class part 1
QT program font becomes larger on computers with different resolutions, overflowing controls
[opengl] advanced chapter of texture - principle of flowmap
Global and Chinese market of trimethylamine 2022-2028: Research Report on technology, participants, trends, market size and share
7-3 count the number of words in a line of text
Bucket sorting in C language
C language to implement a password manager (under update)
Global and Chinese market of solder bars 2022-2028: Research Report on technology, participants, trends, market size and share
Find books ()
4-33--4-35
Zzuli:1052 sum of sequence 4
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
dllexport和dllimport
Several sentences extracted from the book "leather bag"
[wechat applet] wxss template style
C language DUP function
Detailed explanation of four modes of distributed transaction (Seata)
cpu飙升排查方法
[opengl] pre bake using computational shaders
5.4-5.5