Golang 19 ms two pointers


  • 0
    R
    func firstUniqChar(s string) int {
        if len(s) == 0 { return -1}
        lenny:=len(s)
        if lenny == 1 { return 0 }
        
        cc := []byte(s)
        slow:=0
        fast:=1
        count:=make([]int, 256)
        count[cc[slow]]++
        for fast<lenny {
            count[cc[fast]]++
            for slow < lenny && count[cc[slow]] > 1 { slow++}
            if slow >= lenny { return -1 }
            if count[cc[slow]] == 0 {
                count[cc[slow]]++
                fast = slow
            }
            fast++
        }
        return slow
    }
    

Log in to reply
 

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