We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7e7fbc5 commit 1e12314Copy full SHA for 1e12314
0224LJH/202511/21 PGM 숫자 변환하기.md
@@ -0,0 +1,34 @@
1
+```java
2
+import java.io.*;
3
+import java.util.*;
4
+
5
+class Solution {
6
+ public int solution(int x, int y, int n) {
7
+ int[] dp = new int[1_000_001];
8
+ Arrays.fill(dp,Integer.MAX_VALUE/2);
9
+ dp[x] = 0;
10
11
+ for (int i = x; i <= y; i++){
12
+ if (dp[i] >= Integer.MAX_VALUE/2) continue;
13
+ int next = i+n;
14
+ int mul2 = i*2;
15
+ int mul3 = i*3;
16
17
+ if ( next <= 1000_000){
18
+ dp[next] = Math.min(dp[i]+1,dp[next]);
19
+ }
20
+ if ( mul2 <= 1000_000){
21
+ dp[mul2] = Math.min(dp[i]+1,dp[mul2]);
22
23
+ if ( mul3 <= 1000_000){
24
+ dp[mul3] = Math.min(dp[i]+1,dp[mul3]);
25
26
27
28
29
30
+ int answer = (dp[y]!=Integer.MAX_VALUE/2?dp[y]:-1);
31
+ return answer;
32
33
+}
34
+```
0 commit comments