You are climbing a stair case. n steps to reach to the top.climb 1 or 2 steps.distinct ways to climb to top


  • -1
    V
    int climbStairs(int n) {
    double sum=0,i,temp2,ct=0,rem=0,remfac=1,temp2fac=1,totfac=1,tot;
     if(0==n || 1==n || 2==n)
            return n;
    else
    {
        temp2=n;
        while(temp2>1)
        {
            temp2=temp2-2;
            sum++;
        }
        while(sum>=0)
        {
            rem=n-(sum*2);
            for(i=1;i<=rem;i++)
            remfac=remfac*i;
            for(i=1;i<=sum;i++)
            temp2fac=temp2fac*i;
            tot=rem+sum;
            for(i=1;i<=tot;i++)
            totfac=totfac*i;
            ct=ct+(totfac/(remfac*temp2fac));
            sum--;
            remfac=1;
            temp2fac=1;
            totfac=1;
        }
        return ct;
    }
        }
    

    44/45 test cases passed. Any idea why input 44 does not pass? What is it that I am missing in the code. Thanks!

    Input: 44
    Output: 1134903169
    Expected: 1134903170


  • 0
    V

    Solved - long double instead of double works


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.