-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuniqueCharacter.py
43 lines (42 loc) · 1.16 KB
/
uniqueCharacter.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
31
32
33
34
35
36
37
38
39
40
41
42
43
class Solution():
def firstUniqChar(self, s):
dictionary = {}
returnInd = len(s)
print("dict 1 ", dictionary)
flag = 0
for ind, item in enumerate(s):
if item in dictionary:
dictionary[item] = -1
print("dict 2 ", dictionary)
else:
dictionary[item] = ind
print("dict 3 ", dictionary)
for item in dictionary:
print("item 1", item)
if dictionary[item]!= -1:
print("dict[item] ", dictionary[item])
if returnInd > dictionary[item]:
flag = 1
returnInd = dictionary[item]
print("returnInd ", returnInd)
#
def firstUniqChar1(self, s):
"""
:type s: str
:rtype: int
"""
res = len(s)
c = "abcdefghijklmnopqrstuvwxyz"
for x in c:
m = s.find(x)
print("m and x", m, x)
if m != -1:
n = s.rfind(x)
print("m, n, x ", m,n,x)
if m==n:
res = min(res,n)
print("res ", res)
return (res if res<len(s) else -1)
s = "leet"
sol = Solution()
print(sol.firstUniqChar1(s))