Share my 0ms java solution,O(1) time & space complexity


  • 0
    H
    public int climbStairs(int n) {
        n = n+1;
    	double sqrt5 = Math.sqrt(5);
    	double ret = (1/sqrt5)*(Math.pow((1+sqrt5)/2, n)-Math.pow((1-sqrt5)/2, n));
    	return (int)ret;
    }

Log in to reply
 

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