MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / firstUniqChar

Method firstUniqChar

String/FirstUniqueCharacterInAString.py:27–48  ·  view source on GitHub ↗

:type s: str :rtype: int

(self, s)

Source from the content-addressed store, hash-verified

25"""
26class Solution(object):
27 def firstUniqChar(self, s):
28 """
29 :type s: str
30 :rtype: int
31 """
32
33 x = {}
34
35 for i in s:
36 try:
37 x[i] += 1
38 except:
39 x[i] = 1
40
41 for i in x.keys():
42 if x[i] > 1:
43 x.pop(i)
44
45 for i in range(len(s)):
46 if s[i] in x:
47 return i
48 return -1

Callers

nothing calls this directly

Calls 1

popMethod · 0.45

Tested by

no test coverage detected