2 lines in Python

  • 0
    class Solution(object):
        def firstUniqChar(self, s):
            :type s: str
            :rtype: int
            res = [s.index(k1) for k1,v1 in {k: s.count(k) for k in set(s)}.items() if v1==1]
            return min(res) if res else -1

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.