mirror of
https://github.com/prdlk/leetcode.git
synced 2026-11-02 13:12:44 +00:00
feat(problems): add implementation for first unique character in a string
This commit is contained in:
1 parent
9b9428db47
commit
d46fb529c0
1 file changed
+11
-1
@@ -43,5 +43,15 @@
|
||||
*/
|
||||
|
||||
func firstUniqChar(s string) int {
|
||||
|
||||
freq := map[rune]int{}
|
||||
for _, c := range s {
|
||||
freq[c]++
|
||||
}
|
||||
|
||||
for i, c := range s {
|
||||
if freq[c] == 1 {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
Reference in new issue
Block a user