Notice
                              
                          
                        
                          
                          
                            Recent Posts
                            
                        
                          
                          
                            Recent Comments
                            
                        
                          
                          
                            Link
                            
                        250x250
    
    
  | 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 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 | 29 | 
| 30 | 
                            Tags
                            
                        
                          
                          - Algorithm
 - array
 - greedy
 - hash table
 - dynamic programming
 - java
 - 백준
 - 변수
 - leetcode
 - 자료형
 - math
 - Python
 - JavaScript
 - 알고리즘
 - sorting
 - scss
 - JavaSceipt
 - computed
 - 프로그래머스
 - HTML
 - 파이썬
 - github
 - JS
 - string
 - 자료구조
 - SasS
 - vue.js
 - 컴포넌트
 - 코딩테스트
 - CSS
 
                            Archives
                            
                        
                          
                          - Today
 
- Total
 
Posis
[LeetCode][JavaScript] 70. Climbing Stairs 본문
[LeetCode][JavaScript] 70. Climbing Stairs
문제 출처: https://leetcode.com/problems/climbing-stairs/
Climbing Stairs - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com

[직접 푼 코드]
var climbStairs = function (n) {
  if (n < 3) return n;
  let first = 1;
  let second = 2;
  for (let i = 3; i <= n; i++) {
    const current = first + second;
    first = second;
    second = current;
  }
  return second;
};
[문제 풀이]
1. Input값이 3 미만일 경우 그대로 반환합니다.
2. Input이 4일 경우 2의 경우의 수와 3의 경우의 수를 합치면 4의 경우의 수가 나옵니다.
p.s 그림판으로 경우의 수를 써가면서 하다보니 찾은 규칙입니다.
알고리즘 스터디: https://github.com/ROUTINE-STUDY/Algorithm
GitHub - ROUTINE-STUDY/Algorithm: 초보 알고리즘 스터디 / 누구나 참여 가능
초보 알고리즘 스터디 / 누구나 참여 가능 :runner:. Contribute to ROUTINE-STUDY/Algorithm development by creating an account on GitHub.
github.com
누구나 참여 가능한 알고리즘 스터디입니다.
알고리즘뿐만 아니라 개발을 하면서 겪은 이슈, 이론을 정리하는 Routine-Study를 운영 중입니다.
728x90
    
    
  '알고리즘 > leetcode' 카테고리의 다른 글
| [LeetCode][JavaScript] 561. Array Partition I (0) | 2021.07.29 | 
|---|---|
| [LeetCode][JavaScript] 1436. Destination City (0) | 2021.07.29 | 
| [LeetCode][JavaScript] 1323. Maximum 69 Number (0) | 2021.07.29 | 
| [LeetCode][JavaScript] 389. Find the Difference (0) | 2021.07.29 | 
| [LeetCode][JavaScript] 66. Plus One (0) | 2021.07.28 |