Created
December 26, 2019 12:56
-
-
Save luoheng23/976042399f65ad4aa988add174aed8ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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