Skip to content

Commit 3138da7

Browse files
author
hero
committed
firstUniqChar
1 parent cbf3ecd commit 3138da7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

leet_code/firstUniqChar_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package leet_code
2+
3+
import "testing"
4+
5+
func firstUniqChar(s string) int {
6+
var (
7+
raneMap = make(map[rune]int, len(s))
8+
)
9+
for _, v := range s {
10+
raneMap[v]++
11+
}
12+
for i, v := range s {
13+
if val, ok := raneMap[v]; ok {
14+
if val == 1 {
15+
return i
16+
}
17+
}
18+
}
19+
return -1
20+
}
21+
22+
func Test_firstUniqChar(t *testing.T) {
23+
t.Log(firstUniqChar("loveleetcode"))
24+
}

0 commit comments

Comments
 (0)