Open yeonghwanjeon opened 5 years ago
다른 풀이
Counter 쓰면 ordered 되어 나오는 듯
class Solution:
def firstUniqChar(self, s):
"""
:type s: str
:rtype: int
"""
# build hash map : character and how often it appears
count = collections.Counter(s)
# find the index
index = 0
for ch in s:
if count[ch] == 1:
return index
else:
index += 1
return -1
문제 풀이
Hash map 문제 활용