Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- date
- 프로그래머스
- OAuth
- 자바스크립트
- GIT
- leetcode
- spring security
- 스프링
- map()
- gitlab
- 자바
- Spring Cloud
- 코딩테스트
- JS
- jQuery
- 스프링 클라우드
- 유레카
- spring boot
- STS
- Java
- 도커
- map
- SpringBoot
- 비동기
- JavaScript
- IntelliJ
- docker
- 스프링부트
- Spring
- EUREKA
Archives
- Today
- Total
RATSENO
[Leetcode P70]피보나치 수열 본문
package example.leetcode;
public class P70 {
public int climbStairs(int n) {
/*
n=0
------------->0
n=1
1
------------->1
n=2
1,1
2
------------->2
n=3
1,1,1
1,2
2,1
------------->3
n=4
1,1,1,1
1,1,2
1,2,1
2,1,1
2,2
-------------->5
n=5
1,1,1,1,1
1,1,1,2
1,1,2,1
1,2,1,1
2,1,1,1
1,2,2
2,1,2
2,2,1
--------------->8
피보나치 수열
*/
// base cases
if(n <= 0) return 0;
if(n == 1) return 1;
if(n == 2) return 2;
int one_step_before = 2;
int two_steps_before = 1;
int all_ways = 0;
for(int i=2; i<n; i++){
all_ways = one_step_before + two_steps_before;
two_steps_before = one_step_before;
one_step_before = all_ways;
}
return all_ways;
}
}
'DEV > 코딩테스트 문제풀기' 카테고리의 다른 글
[Leetcode P67]2진수 더하기 (0) | 2021.03.22 |
---|---|
[JAVA]프로그래머스(level1) - 체육복 (0) | 2020.03.18 |
[Leetcode]Valid Parentheses (0) | 2020.03.16 |
[Leetcode]Longest Common Prefix (0) | 2020.03.16 |
[Leetcode]Roman to Integer (0) | 2020.03.16 |
Comments