Interview questions have 50 steps, you can take one or two steps at a time, how many ways are there

There are 50 steps, you can take one or two steps at a time, how many ways are there
Programs list all possibilities

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class GoStairs {

	private List<Integer> stepStlye = new ArrayList<Integer>();
	public static final int STAIRS_COUNT = 10;

	public void goStairs(int leftStairsCount) {
		if (leftStairsCount - 1 >= 0) {
			stepStlye.add(1);
			leftStairsCount = leftStairsCount - 1;
			goStairs(leftStairsCount);
			leftStairsCount = leftStairsCount + 1;
			stepStlye.remove(stepStlye.size() - 1);
		}
		if (leftStairsCount - 2 >= 0) {
			stepStlye.add(2);
			leftStairsCount = leftStairsCount - 2;
			goStairs(leftStairsCount);
			leftStairsCount = leftStairsCount + 2;
			stepStlye.remove(stepStlye.size() - 1);
		}
		if (leftStairsCount == 0) {
			System.out.println(Arrays.toString(stepStlye.toArray(new Integer[0])));
			return;
		}
	}

	public static void main(String[] args) {
		GoStairs ladder = new GoStairs();
		ladder.goStairs(STAIRS_COUNT);
	}
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326925997&siteId=291194637