Why does my Java solution only beat 9.16%


  • 0
    J
    public class Solution {
        public int climbStairs(int n) {
            if (n == 1)
            {
                return 1;
            }
            if (n == 2)
            {
                return 2;
            }
            int prevPrev = 1, prev = 2, curr = prevPrev + prev;
            for (int i = 3; i <= n; i++)
            {
                curr = prevPrev + prev;
                prevPrev = prev;
                prev = curr;
            }
            return curr;
        }
    }

Log in to reply
 

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