DevYoon
[ํ๋ก๊ทธ๋๋จธ์ค] N์ผ๋ก ํํ (Python) ๋ณธ๋ฌธ
link ๐ https://programmers.co.kr/learn/courses/30/lessons/42895
def solution(N, number):
if N == number:
return 1
dp = [set() for _ in range(9)]
for i in range(1, 9):
dp[i].add(int(str(N)*i))
for j in range(1, i):
for y in dp[j]:
for x in dp[i-j]:
dp[i].add(y+x)
dp[i].add(y-x)
dp[i].add(y*x)
if x != 0:
dp[i].add(y//x)
if number in dp[i]:
return i
dp.append(dp[i])
return -1
โ๏ธ ๋ฉ๋ชจ
- ์ค๋ณต์ ์ํด set ์ฌ์ฉ
- set์ add, ์ธ๋ฑ์ฑ ๋ถ๊ฐ๋ฅ