题目描述

在一个字符串(0<=字符串长度<=10000,全部由字母组成)中找到第一个只出现一次的字符,并返回它的位置, 如果没有则返回 -1(需要区分大小写).(从0开始计数)

  1. class Solution:
  2. def FirstNotRepeatingChar(self, s):
  3. # write code here
  4. if len(s) == 0:
  5. return -1
  6. a = []
  7. for i in range(len(s)):
  8. if s.count(s[i])==1:
  9. a.append(i)
  10. return a[0]
  11. return -1