70. Climbing Stairs

JJ·2020년 11월 30일
0

Algorithms

목록 보기
5/114
post-thumbnail
class Solution {
    public int climbStairs(int n) {
        int order = n / 2;
        return (int) Math.pow(2, order);
    }
}

Initially, didn't think about the ordering.

1 - 1
2 - (11) (2)
3 - (111) (12) (21)
4 - (1111) (121) (211) (112) (22)
대박….!

class Solution {
    public int climbStairs(int n) {
        int fir = 0; 
        int sec = 1;
        int order = 1;
        for (int i = 1; i <= n; i++) {
            order = fir + sec;
            fir = sec;
            sec = order;
        }
        
        return order;
    }

Runtime: 0 ms, faster than 100.00% of Java online submissions for Climbing Stairs.
Memory Usage: 35.3 MB, less than 97.04% of Java online submissions for Climbing Stairs.
천재같다.

0개의 댓글