Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.


  • 0
    S

    func firstUniqChar(s string) int {
    freq := make(map[rune]int)
    for _, v := range s {
    freq[v]++
    }
    for i, v := range s {
    if freq[v] == 1 {
    return i
    }
    }
    return -1
    }


Log in to reply
 

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