func callPrintSteps(n int) {
printStepChoices(make([]int,0),n)
}
func printStepChoices(pre []int, n int) {
if n < 1 {
fmt.Println(pre)
return
}
if n >= 2 {
printStepChoices( append(pre, 2),n-2)
}
printStepChoices( append(pre, 1),n-1)
}
如果变成“青蛙跳台阶”,每次条1,2...n个台阶,打印所有可能走法:
func jumpNStepOneTime(pre []int,n int) {
if n < 1 {
fmt.Println(pre)
return
}
for i:=n;i>0;i--{
jumpNStepOneTime(append(pre,i), n-i)
}
}