You are climbing a staircase that has n steps. You can take the steps either 1 or 2 at a time. Calculate how many distinct ways you can climb to the top of the staircase.

Example

Input/Output

풀이

int solution(int n) {
    if (n == 1) return 1;
    if (n == 2) return 2;
    
    int [] arr = new int [n + 1];
    // 1 step
    arr[1] = 1;
    // 1, 1 steps
    // 2 steps
    arr[2] = 2;
    
    for (int i = 3; i <= n; i ++) {
        arr[i] = arr[i - 1] + arr[i - 2];
    }
    
    return arr[n];
}