fibonacci series approach in java


  • 0
    N

    public int climbStairs(int n) {
    int n1 = 1, n2 = 2;
    if(n == 1)
    return n1;
    if(n == 2)
    return n2;
    int total = 0;
    for(int i = 3; i <= n; i++){
    total = n1 + n2;
    n1 = n2;
    n2 = total;
    }
    return total;
    }


Log in to reply
 

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