zoukankan      html  css  js  c++  java
  • Lc70_爬楼梯

    //假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 
    //
    // 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢? 
    //
    // 注意:给定 n 是一个正整数。 
    //
    // 示例 1: 
    //
    // 输入: 2
    //输出: 2
    //解释: 有两种方法可以爬到楼顶。
    //1.  1 阶 + 1 阶
    //2.  2 阶 
    //
    // 示例 2: 
    //
    // 输入: 3
    //输出: 3
    //解释: 有三种方法可以爬到楼顶。
    //1.  1 阶 + 1 阶 + 1 阶
    //2.  1 阶 + 2 阶
    //3.  2 阶 + 1 阶
    // 
    // Related Topics 动态规划
    
    package leetcode.editor.cn;
    //Java:爬楼梯
    public class P70ClimbingStairs{
        public static void main(String[] args) {
            Solution solution = new P70ClimbingStairs().new Solution();
            // TO TEST
            System.out.println(solution.climbStairs(1));
        }
        //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int climbStairs(int n) {
    //        if(n==1){
    //            return 1;
    //        }else if(n==2){
    //            return 2;
    //        }else{
    //            return climbStairs(n-2)+climbStairs(n-1);
    //        }
            int[] res = new int[n+1];
            res[0]=1;
            res[1]=2;
            if(n==1){
                return res[0];
            }
            if(n==2){
                return res[1];
            }
            for (int i =2; i <n ; i++) {
                res[i]=res[i-1]+res[i-2];
            }
            return res[n-1];
    
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)
    
    }
    
  • 相关阅读:
    浏览器跨域访问WebApi
    外部主机无法访问IIS发布的网站
    在VisualStudio中远程调试IIS站点
    关于跨域请求的一些解决方案
    MVC与WebApi中的异常过滤器
    委托与事件
    C#中的属性
    C#中的索引
    Equals与==的区别
    关于跨域响应头Access-Control-Allow-Headers的一些说明
  • 原文地址:https://www.cnblogs.com/xiaoshahai/p/13331331.html
Copyright © 2011-2022 走看看