Skip to content

Commit 6f893fa

Browse files
authored
Create firstUniqueChar.py
1 parent 570b682 commit 6f893fa

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Kangli/Strings/firstUniqueChar.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution(object):
2+
def firstUniqChar(self, s):
3+
d={}
4+
for c in s:
5+
d[c] = 1 if c not in d else d[c] +1
6+
for i, c in enumerate(s):
7+
if d[c] == 1:
8+
return i
9+
return -1
10+
11+
#build a hash of letter counts, then iterate through s and check count, return index of first letter with count = 1.

0 commit comments

Comments
 (0)