Skip to content

Commit fc100d8

Browse files
authored
Create first_position_unique_character.py
1 parent a48f441 commit fc100d8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

first_position_unique_character.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# coding: utf-8
2+
3+
class Solution:
4+
"""
5+
@param: s: a string
6+
@return: it's index
7+
"""
8+
def firstUniqChar(self, s):
9+
# write your code here
10+
di = {}
11+
for i in range(len(s)):
12+
c = s[i]
13+
if c in di:
14+
di[c] = -1
15+
else:
16+
di[c] = i
17+
ret = len(s)
18+
for k, v in di.items():
19+
if (v != -1) and (v < ret):
20+
ret = v
21+
if ret == len(s):
22+
ret = -1
23+
return ret
24+
25+
# easy: http://lintcode.com/zh-cn/problem/first-position-unique-character/

0 commit comments

Comments
 (0)