Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.
Examples:
s = "leetcode" return 0. s = "loveleetcode", return 2.
Note: You may assume the string contain only lowercase letters.
class Solution(object):def firstUniqChar(self, s):
"""
:type s: str
:rtype: int
"""
if len(s)==1:
return 0
str=list(s)
str.sort()
a=[]
for i in range(0,len(str)):
if (i==0 and str[i]!=str[i+1]) or (i==len(str)-1 and str[i]!=str[i-1]) or (str[i]!=str[i-1] and str[i]!=str[i+1]):
a.append(s.index(str[i]))
if len(a)==0:
return -1
a.sort()
return a[0]