假设你正在爬楼梯,需要n步你才能到达顶部。但每次你只能爬一步或者两步,你能有多少种不同的方法爬到楼顶部? 您在真实的面试中是否遇到过这个题? Yes 哪家公司问你的这个题? Airbnb Alibaba Amazon Apple Baidu Bloomberg Cisco Dropbox Ebay Facebook Google Hulu Intel Linkedin Microsoft NetEase Nvidia Oracle Pinterest Snapchat Tencent Twitter Uber Xiaomi Yahoo Yelp Zenefits 感谢您的反馈 样例 比如n=3,1+1+1=1+2=2+1=3,共有3中不同的方法 返回 3 标签 Expand 动态规划 相关题目 Expand 1 (enumeration),(mathematics),(non-recursion) 容易 斐波纳契数列 32 % 2 (dynamic-programming) 中等 打劫房屋 30 % 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]; } }