Python very easy solution

  • 4
    class Solution(object):
        def firstUniqChar(self, str1):
            :type s: str
            :rtype: int
            for x in str1:
                if str1.find(x)==str1.rfind(x):
                    return str1.find(x)
            return -1

  • 5

    Isn't the worst case complexity O(n^2)?

  • 0

    This is a simple solution, but the complexity is pretty bad. The worst case complexity is O(n^2), when a better solution can yield O(n) complexity.

Log in to reply

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