Who can tell me why this is wrong


  • 0

    int climbStairs(int n)
    {
    int a,s=0,i=0;
    long jiec(int);
    while(i<=n/2)
    {
    a=jiec(n-i)/jiec(i)/jiec(n-2*i);
    s=s+a;
    i++;
    }
    return s;
    }

    long jiec(int k)
    {
    long s=1;
    for(int i=k;k>0;k--)
    s=s*k;
    return s;

    long long s;
    if(k<=1)s=1;
    else
    	s=k*jiec(k-1);
    return s;	
    

    }

    It is right when n<20,but wrong when n is big.for example when n=35.
    I have just learn c for a short ,who can help me to solve this problem.thanks!!!


  • 0

    I have solve the problem,when n is too big, a may be wrong.so i change the method to calculate a and finally pass.


Log in to reply
 

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