mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2026-03-13 10:02:05 +08:00
添加 problem 387
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package leetcode
|
||||
|
||||
func firstUniqChar(s string) int {
|
||||
result := make([]int, 26)
|
||||
for i := 0; i < len(s); i++ {
|
||||
result[s[i]-'a']++
|
||||
}
|
||||
for i := 0; i < len(s); i++ {
|
||||
if result[s[i]-'a'] == 1 {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type question387 struct {
|
||||
para387
|
||||
ans387
|
||||
}
|
||||
|
||||
// para 是参数
|
||||
// one 代表第一个参数
|
||||
type para387 struct {
|
||||
n string
|
||||
}
|
||||
|
||||
// ans 是答案
|
||||
// one 代表第一个答案
|
||||
type ans387 struct {
|
||||
one int
|
||||
}
|
||||
|
||||
func Test_Problem387(t *testing.T) {
|
||||
|
||||
qs := []question387{
|
||||
|
||||
question387{
|
||||
para387{"leetcode"},
|
||||
ans387{0},
|
||||
},
|
||||
|
||||
question387{
|
||||
para387{"loveleetcode"},
|
||||
ans387{2},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Printf("------------------------Leetcode Problem 387------------------------\n")
|
||||
|
||||
for _, q := range qs {
|
||||
_, p := q.ans387, q.para387
|
||||
fmt.Printf("【input】:%v 【output】:%v\n", p, firstUniqChar(p.n))
|
||||
}
|
||||
fmt.Printf("\n\n\n")
|
||||
}
|
||||
Reference in New Issue
Block a user