Skip to content

Commit 7587208

Browse files
Chris WuChris Wu
Chris Wu
authored and
Chris Wu
committed
update
1 parent a392b7b commit 7587208

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
#https://leetcode.com/problems/first-unique-character-in-a-string/
1+
import collections
2+
23
class Solution(object):
34
def firstUniqChar(self, string):
4-
counter = {}
5-
5+
counter = collections.Counter()
66
for char in string:
7-
if char in counter:
8-
counter[char]+=1
9-
else:
10-
counter[char] = 1
11-
12-
for i in range(len(string)):
7+
counter[char]+=1
8+
9+
for i in xrange(len(string)):
1310
char = string[i]
14-
if counter[char]==1:
15-
return i
16-
17-
return -1
11+
if counter[char]==1: return i
12+
13+
return -1

0 commit comments

Comments
 (0)