mirror of
https://github.com/prdlk/leetcode.git
synced 2026-09-16 23:16:26 +00:00
feat(problems): add implementation for first unique character in a string
This commit is contained in:
@@ -40,8 +40,18 @@
|
||||
* • 1 <= s.length <= 10^5
|
||||
*
|
||||
* • s consists of only lowercase English letters.
|
||||
*/
|
||||
*/
|
||||
|
||||
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