package main
import (
"fmt"
)
type Result struct {
C rune // character
L int // count
}
func main() {
fmt.Print(LongestRepetition(""))
}
func LongestRepetition(text string) Result {
if text == "" {
return Result{}
}
var max Result
if len(text) == 1 {
max.C = rune(text[0])
max.L = 1
return max
}
var count Result
for _, s := range text {
if count.C == s {
count.L++
count.C = s
if count.L > max.L {
max.C = count.C
max.L = count.L
}
} else {
count.L = 1
count.C = s
}
}
return max
}
/ 预期 <;kata.Result>;:{C:0,L:0} 达到相等 <;kata.Result>;:{C:98,L:1}
我正在努力完成https://www.codewars.com/kata/586d6cefbcc21eed7a001155/train/go个 连续重复时间最长的字符 在我的测试中,它工作正常 但当我推到CW时,它不能完成弯道测试 请帮帮我 也许我可以在某个地方改进我的代码,或者是我搞错了什么