Java AC Solution with Factorial


  • 0
    W
    import java.math.BigInteger;
    public class Solution {
        public BigInteger fac(int n){
    	    BigInteger num=new BigInteger(String.valueOf(n));
    	    for(int i=n-1;i>0;i--)
    	    num=num.multiply(new BigInteger(String.valueOf(i)));
    	        return num;
    	    } 
    	    
        public int climbStairs(int n) {
            if(n==0)
                return 0;
            int count=0;
            for(int i=0;i<=n;i++){
                for(int j=0;j<=n/2;j++){
                    if((i+2*j)==n){
                        if(i==0||j==0)
                            count++;
                        else{
                            int k=i+j;
                            BigInteger cni=fac(k).divide((fac(i).multiply(fac(k-i))));
                            count+=cni.intValue();
                        }
                    }
                }
            }
    	       return count;
        }
    }
    

Log in to reply
 

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