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.
천재같다.