当前位置:网站首页>剑指 Offer 50. 第一个只出现一次的字符
剑指 Offer 50. 第一个只出现一次的字符
2022-07-16 03:22:00 【愈努力俞幸运】
字典中可以把键值对一起取出来
思路都是遍历
class Solution:
def firstUniqChar(self, s):
dic={}
if s==' ':
return ' '
for i in s:
dic[i]=0
for i in s:
dic[i]+=1
for i in s:
if dic[i]==1:
return i
return ' '
a=Solution()
s = "abaccdeff"
print(a.firstUniqChar(s))
s1=" "
print(a.firstUniqChar(s1))
'''
dic={'a':0,'b':1,2:'d'}
for i in dic:
print(i)#a,b,2
print('a' in dic)#返回True
s=""
for i in s:
print(i,'***')
'''
class Solution:
def firstUniqChar(self, s):
dic={}
for i in s:#s为空字符串不会执行这个for语句
dic[i]= not i in dic#出现次数大于等于2就赋值0
for i in s:
if dic[i]:
return i
return ' '
a = Solution()
s = "abaccdeff"
print(a.firstUniqChar(s))
s1 = " "
print(a.firstUniqChar(s1))'''
#items()-->获取字典中所有key-value对
scores={'张三':100,'李四':98,'王五':45}
item=scores.items()
print(item,type(item))
for i in item:
print(i)
for i,j in item:
print(i,j)
'''
class Solution:
def firstUniqChar(self, s):
dic={}
for i in s:#s为空字符串不会执行这个for语句
dic[i]= not i in dic#出现次数大于等于2就赋值0
for i,j in dic.items():
if j:
return i
return ' '
a = Solution()
s = "abaccdeff"
print(a.firstUniqChar(s))
s1 = " "
print(a.firstUniqChar(s1))边栏推荐
猜你喜欢
随机推荐
(笔记)ideavim和ide冲突解决方法
【机器学习】集成学习 - Ensemble Learning
吉时利万用表DMM6500
金仓数据库 KingbaseES SQL 语言参考手册 (3.1.1.5. 大对象数据类型)
【编程强训5】 连续最大和+统计回文
[swoole series 2.4] websocket service
【HBZ分享】UDP协议讲解
What capabilities should an excellent smart exhibition hall have
The share price fell through! Is Muse going to pay for the "IQ tax"?
金仓数据库 KingbaseES SQL语言参考手册(2. KingbaseES SQL介绍)
PPP综合实验
Source insight 4 what about Chinese garbled code?
【编程强训4】计算糖果+进制转换
安装g2opy框架
Google Earth engine app (GEE) - load a searchable Spector
【机器学习 - 决策树】信息增益
[programming training 5] continuous maximum sum + statistical palindrome
HMS core graphics and image technology shows the latest functions and application scenarios, and accelerates the construction of digital intelligence life
ES6笔记二
剑指 Offer 18. 删除链表的节点
https://leetcode.cn/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/






![[golang | GRC] GRC client streaming client streaming practice](/img/03/81972027ebaa1f5f20b61e35b12ea1.png)

