package cn.jiedada.controller; import java.util.ArrayList; import java.util.List; import java.util.Stack; /** * 爬楼梯 */ class Solution { public static void main(String[] args) { } public int climbStairs(int n) { if (n<1){ return 0; } if (n==1){ return 1; } if (n==2){ return 2; } int a = 1; int b = 2; int temp = 0; //没一次都是上两次的和 for (int i = 3; i <= n; i++) { temp = a + b; a = b; b = temp; } return temp; } }