forked from DmrfCoder/AlgorithmAndDataStructure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path33.py
30 lines (25 loc) · 754 Bytes
/
33.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# -*- coding:utf-8 -*-
class Solution:
def FirstNotRepeatingChar(self, s):
# write code here
size = len(s)
#存储不同字符
array1 = []
#存储不同字符对应的出现次数
array2 = []
#存储不同字符第一次出现的下标
array3=[]
for i in range(size):
if s[i] not in array1:
array1.append(s[i])
array2.append(1)
array3.append(i)
else:
index = array1.index(s[i])
array2[index] += 1
for i in range(len(array2)):
if array2[i] == 1:
return array3[i]
return -1
s=Solution()
print s.FirstNotRepeatingChar('aabbccd')