給定一個字串,找到它的第一個不重複的字元,並返回它的索引。如果不存在,則返回 -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