We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a392b7b commit 7587208Copy full SHA for 7587208
problems/first-unique-character-in-a-string.py
@@ -1,17 +1,13 @@
1
-#https://leetcode.com/problems/first-unique-character-in-a-string/
+import collections
2
+
3
class Solution(object):
4
def firstUniqChar(self, string):
- counter = {}
5
-
+ counter = collections.Counter()
6
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)):
+ counter[char]+=1
+ for i in xrange(len(string)):
13
char = string[i]
14
- if counter[char]==1:
15
- return i
16
17
- return -1
+ if counter[char]==1: return i
+ return -1
0 commit comments