Leetcode 剑指 Offer 50.第一个只出现一次的字符
1 题目描述(Leetcode题目链接)
在字符串 s 中找出第一个只出现一次的字符。如果没有,返回一个单空格。 s 只包含小写字母。
s = "abaccdeff"
返回 "b"
s = ""
返回 " "
2 题解
计数。
class Solution:
def firstUniqChar(self, s: str) -> str:
dic = collections.Counter(s)
for i in s:
if dic[i] == 1:
return i
return " "