Skip to content

Commit

Permalink
Merge pull request #733 from Jay-Mo-99/main
Browse files Browse the repository at this point in the history
[Jay-Mo-99] Week 2
  • Loading branch information
SamTheKorean authored Dec 22, 2024
2 parents 0e775c1 + db88752 commit 8277ec9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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

return a

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

0 comments on commit 8277ec9

Please sign in to comment.