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 570b682 commit 6f893faCopy full SHA for 6f893fa
Kangli/Strings/firstUniqueChar.py
@@ -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