添加 problem 387

This commit is contained in:
YDZ
2019-07-15 23:21:46 +08:00
parent f360d4e3fc
commit d1b1f7bdf2
2 changed files with 61 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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")
}