mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 20:04:43 +01:00
20210105
This commit is contained in:
21
20210105/main.go
Normal file
21
20210105/main.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func countBalance(s string) int {
|
||||||
|
count, rCount, lCount := 0, 0, 0
|
||||||
|
for i := 0; i < len(s); i++ {
|
||||||
|
if s[i] == 'R' {
|
||||||
|
rCount++
|
||||||
|
} else if s[i] == 'L' {
|
||||||
|
lCount++
|
||||||
|
}
|
||||||
|
if rCount > 0 && rCount == lCount {
|
||||||
|
lCount, rCount = 0, 0
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
29
20210105/main_test.go
Normal file
29
20210105/main_test.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func Test_countBalance(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
s string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"test1",
|
||||||
|
args{
|
||||||
|
"RLRRLLRLRL",
|
||||||
|
},
|
||||||
|
4,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := countBalance(tt.args.s); got != tt.want {
|
||||||
|
t.Errorf("countBalance() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user