public class Solution { /** * @param n: An integer * @return: An integer */ public int climbStairs(int n) { // write your code here int a[] = new int[1000000]; a[0] = 1; a[1] = 1; for(int i=2;i<=n;i++){ a[i] = a[i-1] + a[i-2]; } return a[n]; } }
假设你正在爬楼梯,需要n步你才能到达顶部。但每次你只能爬一步或者两步,你能有多少种不同的方法爬到楼顶部?您在真实的面试中是否遇到过这个题?Yes哪家公司问你的这个题?AirbnbAlibaba Amazon Apple Baidu Bloomberg Cisco Dropbox Ebay Facebook Google Hulu Intel