当前位置:网站首页>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 ' ';
}
};边栏推荐
- 【注意力机制】【首篇ViT】DETR,End-to-End Object Detection with Transformers网络的主要组成是CNN和Transformer
- 5-1 blocking / non blocking, synchronous / asynchronous
- Zzuli:1041 sum of sequence 2
- 4-29——4.32
- [opengl] face pinching system
- [combinatorics] permutation and combination (set combination, one-to-one correspondence model analysis example)
- 2022/02/14
- 零拷贝底层剖析
- ASTC texture compression (adaptive scalable texture compression)
- 7-9 one way in, two ways out (25 points)
猜你喜欢

Implement Gobang with C language

创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03

Byte practice plane longitude 2

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

cpu飙升排查方法

Centos7 deployment sentry redis (with architecture diagram, clear and easy to understand)

C language to realize mine sweeping

Open under vs2019 UI file QT designer flash back problem

Pytoch deep learning and target detection practice notes

How does vs+qt set the software version copyright, obtain the software version and display the version number?
随机推荐
2021-10-16 initial programming
Detailed explanation of four modes of distributed transaction (Seata)
Zzuli:1054 monkeys eat peaches
ASTC texture compression (adaptive scalable texture compression)
.NET六大设计原则个人白话理解,有误请大神指正
Mmdetection learning rate and batch_ Size relationship
The picture quality has been improved! LR enhancement details_ Lightroom turns on AI photo detail enhancement: picture clarity increases by 30%
Zzuli:1055 rabbit reproduction
Bucket sorting in C language
406. 根据身高重建队列
【微信小程序】WXSS 模板样式
C language to implement a password manager (under update)
Yolov5系列(一)——网络可视化工具netron
Zzuli:1042 sum of sequence 3
Time conversion ()
C string format (decimal point retention / decimal conversion, etc.)
7-10 stack of hats (25 points) (C language solution)
How does vs+qt set the software version copyright, obtain the software version and display the version number?
PHP GD image upload bypass
[combinatorics] permutation and combination (set combination, one-to-one correspondence model analysis example)