feat(problems): add implementation for first unique character in a string

This commit is contained in:
Prad Nukala
2026-08-13 21:57:10 -04:00
parent 9b9428db47
commit d46fb529c0
@@ -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
}