
正文
【leetcode 简单】 第九十题 字符串中的第一个唯一字符
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。
案例:
s = "leetcode"
返回 0. s = "loveleetcode",
返回 2.
class Solution(object):
def firstUniqChar(self, s):
"""
:type s: str
:rtype: int
"""
s_len=len(s)
for i in "abcdefghijklmnopqrstuvwxyz":
start_f = s.find(i)
if start_f != -1 and start_f == s.rfind(i):
s_len = min(start_f,s_len)
return s_len if s_len != len(s) else -1








