zoukankan      html  css  js  c++  java
  • [LeetCode]Climbing Stairs

    称号:给定一个int整数类型n,它代表了楼梯的阶。每一个可能的步骤时,楼梯,有可能采取两个步骤,求完成n楼梯有多少种不同的方法

    算法:递归是最简单的方法,但超时。递归转换的递推公式:f(n) = f(n-1)+f(n-2)

    public class Solution {
        public int climbStairs(int n) {
    			final int STAIRS = 50;
    	        int[] nSteps = new int[STAIRS];
    	        nSteps[0] = 0;
    	        nSteps[1] = 1;
    	        nSteps[2] = 2;
    	        nSteps[3] = 3;
    	        for (int i=4; i<STAIRS; ++i) {
    	        	nSteps[i] = nSteps[i-1] + nSteps[i-2];
    	        }
    	        
    	        return nSteps[n];
    	    }
    }

  • 相关阅读:
    django 2.0 path
    Django
    ORM
    Django简介
    web框架
    HTTP协议
    web应用
    索引
    pyMysql模块
    视图、触发器、存储过程、函数
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4601867.html
Copyright © 2011-2022 走看看