We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f6eb215 commit 4833179Copy full SHA for 4833179
1 file changed
LiiNi-coder/202511/09 PGM 숫자 변환하기.md
@@ -0,0 +1,36 @@
1
+```java
2
+import java.util.*;
3
+
4
+class Solution {
5
+ private static int MAX = 1_000_001;
6
+ public int solution(int x, int y, int n) {
7
+ int answer = 0;
8
+ Queue<int[]> q = new ArrayDeque<int[]>();
9
+ q.offer(new int[]{0, x});
10
+ boolean[] visited = new boolean[MAX];
11
+ visited[x] = true;
12
+ boolean hasAnswer = false;
13
+ int count = 0, value;
14
+ while(!q.isEmpty()){
15
+ int[] temp = q.poll();
16
+ count = temp[0];
17
+ value = temp[1];
18
+ if(value == y){
19
+ hasAnswer = true;
20
+ break;
21
+ }
22
+ for(int new_value: new int[]{value+n, value*2, value*3}){
23
+ if(new_value >= MAX){
24
+ continue;
25
26
+ if(visited[new_value])
27
28
+ q.offer(new int[]{count+1, new_value});
29
+ visited[new_value] = true;
30
31
32
33
+ return (hasAnswer)? count: -1;
34
35
+}
36
+```
0 commit comments