mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 23:04:42 +01:00
20210121
This commit is contained in:
31
20210121/main.go
Normal file
31
20210121/main.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import "strings"
|
||||
|
||||
const balloon = "balloon"
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
|
||||
func maxNumberOfBalloons(text string) int {
|
||||
nt := text
|
||||
lt := text
|
||||
end := false
|
||||
count := 0
|
||||
for {
|
||||
for _, c := range balloon {
|
||||
nt = strings.Replace(lt, string(c), "", 1)
|
||||
if nt == lt {
|
||||
end = true
|
||||
break
|
||||
}
|
||||
lt = nt
|
||||
}
|
||||
if end {
|
||||
break
|
||||
}
|
||||
count++
|
||||
}
|
||||
return count
|
||||
}
|
||||
43
20210121/main_test.go
Normal file
43
20210121/main_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func Test_maxNumberOfBalloons(t *testing.T) {
|
||||
type args struct {
|
||||
text string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want int
|
||||
}{
|
||||
{
|
||||
"test1",
|
||||
args{
|
||||
"nlaebolko",
|
||||
},
|
||||
1,
|
||||
},
|
||||
{
|
||||
"test2",
|
||||
args{
|
||||
"loonbalxballpoon",
|
||||
},
|
||||
2,
|
||||
},
|
||||
{
|
||||
"test3",
|
||||
args{
|
||||
"leetcode",
|
||||
},
|
||||
0,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := maxNumberOfBalloons(tt.args.text); got != tt.want {
|
||||
t.Errorf("maxNumberOfBalloons() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user