-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path387.py
26 lines (24 loc) · 960 Bytes
/
387.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
__________________________________________________________________________________________________
sample 32 ms submission
class Solution:
def firstUniqChar(self, s: str) -> int:
uniq = []
first = len(s)
for letter in "abcdefghijklmnopqrstuvwxyz":
pos = s.find(letter)
rep = s.rfind(letter)
if pos == rep and pos >= 0:
if pos < first:
first = pos
return first if first < len(s) else -1
__________________________________________________________________________________________________
sample 13044 kb submission
class Solution:
def firstUniqChar(self, s: str) -> int:
from collections import Counter
c = Counter(s)
for i in range(len(s)):
if c[s[i]] == 1:
return i
return -1
__________________________________________________________________________________________________