Accepted fast one-line solution(JAVA)


  • 0

    Actually it is a divide and conquer way:

    public class Solution {
        public int climbStairs(int n) {
            return n <= 3 ? n : climbStairs(n/2)*climbStairs(n - n/2) + climbStairs(n/2 - 1) * climbStairs(n - n/2 - 1);
        }
    }

  • 0
    T

    It looks like O(N^2). Far from fast.


  • 0

    Yes, you are right. My mistake. Not fast but interesting! LOL


Log in to reply
 

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