Skip to content
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
14 changes: 14 additions & 0 deletions climbing-stairs/mandel-17.py
Copy link
Contributor

Choose a reason for hiding this comment

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

현재 칸에 도달할 수 있는 방법의 수 = 2칸 아래의 계단에 도달할 수 있는 방법의 수(2칸을 한 번에 오르면 현재 칸)+1칸 아래의 계단에 도달할 수 있는 방법의 수(1칸을 오르면 현재 칸)으로 DP식을 세우면 좀 더 효율적으로 문제를 해결할 수 있을 것 같습니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import collections

class Solution:
num_dict = collections.defaultdict(int)

def climbStairs(self, n: int) -> int:
if n <= 2:
return n

if self.num_dict[n]:
return self.num_dict[n]

self.num_dict[n] = self.climbStairs(n-1) + self.climbStairs(n-2)
return self.num_dict[n]
14 changes: 14 additions & 0 deletions valid-anagram/mandel-17.py
Copy link
Contributor

Choose a reason for hiding this comment

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

간단하게 Counter를 활용하면 더 간결하게 구현할 수 있을 것 같습니다

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import collections

class Solution:
num_dict = collections.defaultdict(int)

def climbStairs(self, n: int) -> int:
if n <= 2:
return n

if self.num_dict[n]:
return self.num_dict[n]

self.num_dict[n] = self.climbStairs(n-1) + self.climbStairs(n-2)
return self.num_dict[n]