題目描述
在一個字符串(0<=字符串長度<=10000,全部由字母組成)中找到第一個只出現一次的字符,並返回它的位置, 如果沒有則返回 -1(需要區分大小寫)
思路
遍歷字符串,找到那個第一個count計數為1的值,返回它的下標值。。
解答
class Solution: def FirstNotRepeatingChar(self, s): # write code here if not s or len(s)>10000: return -1 else: for i in s: if s.count(i) == 1: return s.index(i)