Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Jay-Mo-99] Week 2 #733

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions climbing-stairs/Jay-Mo-99.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
 #해석
#피보나치 수열을 이용하여 특정 범위마다 1과 2를 활용한 방법의 수를 계산한다.
#a=1, a=2 로 초기 셋팅 후 반복문마다 a와 b를 업데이트 한다.
# a는 현재 계단의 경우의 수, b는 다음 계단의 경우의 수로 설정한다.
# 반복문의 결과로 n번째 계단을 오르는 방법의 수(a)를 반환한다.


#Big O
#N: 매개변수 n의 크기(계단 갯수)

#Time Complexity: O(N)
#- for loop 는 n-1번 : O(N)

#Space Complexity: O(1)
#- 상수 a,b만 사용 : O(1)

class Solution(object):
def climbStairs(self, n):
"""
:type n: int
:rtype: int
"""
a,b = 1,2 #F(0) = 1, F(1) =2
for i in range(1,n):
a,b = b, a+b #Update a and b each iteration
#Fn = Fn-1 + Fn-2

Comment on lines +23 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파이썬의 강점이 잘 활용된것 같아요!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

튜플할당 방식을 쓰니까 가독성이 좋네요! 처음 알게돼서 신기하네요 :)

return a

Empty file added valid-anagram/Jay-Mo-99.py
Empty file.
Loading