Fibonacci sequence!DP


  • 4
    S
    public class Solution {
        public int ClimbStairs(int n) {
           if (n <= 1) return 1;
    
                int n1 = 1, n2 = 1;
                int ret=0;
                for (int i = 0; i < n-1; i++)
                {
                    ret = n1 + n2;
                    n1 = n2;
                    n2 = ret;
                }
                return ret;
        }
    }

  • 0
    M

    Same with u.


Log in to reply
 

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