• 09-2:跳台阶


    /**
     * 面试题9:
     * 题目2:跳台阶
     * 一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
     */
    public class _09_2_frog {
        public static void main(String[] args){
            Solution09_2 solution09_2 = new Solution09_2();
            System.out.println(solution09_2.JumpFloor(5));
        }
    }
    class Solution09_2 {
        //跳台阶
        public int JumpFloor(int target) {
            if(target==1){
                return 1;
            }
            if(target==2){
                return 2;
            }
            return JumpFloor(target-1)+JumpFloor(target-2);
        }
        //变态跳台阶
        int JumpFloorII(int target) {
            return (int) Math.pow(2,target-1);
        }
        //矩形覆盖
        public int RectCover(int target) {
            if(target==0){
                return 0;
            }
            if(target==1){
                return 1;
            }
            if(target==2){
                return 2;
            }
            return RectCover(target-1)+RectCover(target-2);
        }
    }
    
  • 相关阅读:
    openstack生产要素
    None
    nginx优化 tbc
    zabbix开源监控解决方案
    HUGO & Hexo
    mysql数据库-运维合集
    Zabbix Agent ver5.0 批量部署
    CRI containerd
    zabbix聚合图形与Grafana图形展示
    zabbix 监控tomcat
  • 原文地址:https://www.cnblogs.com/andy-zhou/p/6532562.html
Copyright © 2020-2023  润新知