The study notes C # - Algorithm metamorphosis jump stairs

/ * A frog can jump on a Class 1 level, you can also hop on level 2 ...... n It can also jump on stage.
     * Find the frog jumped a grade level n There are many kinds of jumps. * /

using System;

namespace Algorithm9
{
    /*一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。
     * 求该青蛙跳上一个n级的台阶总共有多少种跳法。*/
    class Solution
    {

        public int jumpFloorII(int number)
        {
            // write code here
            return (int)System.Math.Pow(2, number - 1);

            //int a=1; return a<<(number-1); 方法二 位移
            //return 1<<(number-1);

            //方法三 emmm
            /*
             * if (n<=2) return n;
             * int result=0;
             * int result1=1;
             * int result2=2;
             * for(int i=3;i<=n;i++){
             *      result=result1+result2+1;
             *      result1=result1+result2;
             *      result2=result;
             * }
             * return result;           
            */
        }
    }
}

Math does not need to be used directly introduced

Math.Pow (base number, index)

Guess you like

Origin blog.csdn.net/Alina_catty/article/details/91180075