在字符串 s 中找出第一个只出现一次的字符。如果没有,返回一个单空格。
示例:
s = "abaccdeff"
返回 "b"
s = ""
返回 " "
限制:
0 <= s 的长度 <= 50000
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
class Solution(object):
def firstUniqChar(self, s):
"""
:type s: str
:rtype: str
"""
for i in s:
if s.count(i)==1:
return i
return ' '
执行结果:
通过
显示详情
执行用时 :5808 ms, 在所有 Python 提交中击败了6.49%的用户
内存消耗 :13.1 MB, 在所有 Python 提交中击败了100.00%的用户