Skip to content

Instantly share code, notes, and snippets.

@luoheng23
Created December 26, 2019 12:56
Show Gist options
  • Save luoheng23/976042399f65ad4aa988add174aed8ff to your computer and use it in GitHub Desktop.
Save luoheng23/976042399f65ad4aa988add174aed8ff to your computer and use it in GitHub Desktop.
func firstUniqChar(s string) int {
var cnt [26]int
for _, c := range s {
cnt[c-'a']++
}
for i, c := range s {
if cnt[c-'a'] == 1 {
return i
}
}
return -1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment