Share 2 ms C++ code


  • 0
    D
    class Solution {
    

    public:
    int climbStairs(int n) {
    if (n <=0 ) return 0;
    if (n == 1) return 1;

        int i = 1;
        int j = 2;
        
        int count = 3;
        while (count <= n)
        {
            int temp = j;
            j = i + j;
            i = temp;
            ++count;
        }
        return j;
    }
    

    };


Log in to reply
 

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