๐ฆ N์ผ๋ก ํํ
1. ๋ฌธ์ ๋งํฌ
2. ์ฝ๋
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
def solution(N, number):
dp = [set([int(str(N)*i)]) for i in range(1, 9)]
for count in range(8):
for i in range(count):
for left in dp[i]:
for right in dp[count - i - 1]:
dp[count].add(left + right)
dp[count].add(left - right)
dp[count].add(left * right)
if right != 0:
dp[count].add(left // right)
if number in dp[count]:
return count + 1
return -1
์ ํ์ฑ
์ ํ์ฑ ํ ์คํธ ํ ์คํธ 1 ใ ํต๊ณผ (0.85ms, 10.5MB) ํ ์คํธ 2 ใ ํต๊ณผ (0.04ms, 10.4MB) ํ ์คํธ 3 ใ ํต๊ณผ (0.05ms, 10.5MB) ํ ์คํธ 4 ใ ํต๊ณผ (28.66ms, 11.2MB) ํ ์คํธ 5 ใ ํต๊ณผ (16.45ms, 11.1MB) ํ ์คํธ 6 ใ ํต๊ณผ (0.19ms, 10.4MB) ํ ์คํธ 7 ใ ํต๊ณผ (0.20ms, 10.4MB) ํ ์คํธ 8 ใ ํต๊ณผ (24.62ms, 11.3MB) ํ ์คํธ 9 ใ ํต๊ณผ (0.03ms, 10.4MB) ์ฑ์ ๊ฒฐ๊ณผ ์ ํ์ฑ: 100.0 ํฉ๊ณ: 100.0 / 100.0
3. ํด์ค
i ๋ฒ์งธ ์ฐ์ฐ โ j ๋ฒ์งธ ์ฐ์ฐ๊ฒฐ๊ณผ์ j - i - 1 ๋ฒ์งธ ์ฐ์ฐ์ ๋ค์ ์ฌ์ฐ์ฐํ ๊ฒฐ๊ณผ
์ค๋ณต์ ์์ ๊ธฐ ์ํด set ์ผ๋ก ์ ๊ฑฐํ๊ณ ๋น๊ตํ์ฌ
์ด๋ฒ ํ์ฐจ์ ์ฐ์ฐ์ ๋๋ผ ์ ์๋ค๋ฉด ๋ฆฌํด
This post is licensed under CC BY 4.0 by the author.