Skip to content

Commit a3acac5

Browse files
committed
Create first-unique-character-in-a-string.go
1 parent 2787398 commit a3acac5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

first-unique-character-in-a-string.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//https://leetcode.com/problems/first-unique-character-in-a-string/
2+
3+
package leetcode_solutions_golang
4+
5+
func firstUniqChar(s string) int {
6+
count := [26]int{}
7+
for i := 0; i < len(s); i++ {
8+
count[s[i]-'a']++
9+
}
10+
for i := 0; i < len(s); i++ {
11+
if count[s[i]-'a'] == 1 {
12+
return i
13+
}
14+
}
15+
return -1
16+
}

0 commit comments

Comments
 (0)