Skip to content

Instantly share code, notes, and snippets.

@namtx
Created September 24, 2018 07:10
Show Gist options
  • Save namtx/204a517043b8a77a333207ed4521fdad to your computer and use it in GitHub Desktop.
Save namtx/204a517043b8a77a333207ed4521fdad to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func main() {
s := "leetcode"
fmt.Println(firstUniqChar(s))
}
func firstUniqChar(s string) int {
runes := []rune(s)
check := map[rune]int{}
for _, rune := range runes {
check[rune]++
}
for i, rune := range runes {
if check[rune] == 1 {
return i
}
}
return -1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment