subject : In a string (0<= String length <=10000, All by letters ) Find the first character that appears only once , And return to its location , If not, return -1( Case sensitivity required )
Relatively simple , Use one dict, Just loop through it .
Code :
class Solution:
def func(self , s):
if len(s) == 0:
return None
save = dict()
for i in range(len(s)):
if s[i] not in save.keys():
save[s[i]] = i
else:
save.pop(s[i])
res = list(save.keys())[list(save.values()).index(min(list(save.values())))]
print(res)
return save
a = 'abbceeffgg'
a = 'leetcode'
a = 'loveleetcode'
s = Solution()
print(s.func(a))