Skip to content

Commit 11852aa

Browse files
committed
๐Ÿ’ป codetree: solved ๋ฌธ์ž์—ด์˜ ๊ฐœ์ˆ˜
1 parent b4e50d9 commit 11852aa

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.io.*;
2+
import java.util.*;
3+
/**
4+
* 1. ๋ฌธ์ œ์ •๋ณด
5+
* - ์ œ๋ชฉ : ๋ฏธ๋Š” ํšŸ์ˆ˜
6+
* - ๋งํฌ : https://www.codetree.ai/missions/4/problems/number-of-pushes/description
7+
* 2. ํ’€์ดํ•ต์‹ฌ
8+
* - ๋ฌธ์ž์—ด ๋น„๊ต
9+
* 3. ํ’€์ดํ›„๊ธฐ
10+
* - ๊ฐ„๋‹จํ•œ ๋ฌธ์ œ ํ’€์ด
11+
*/
12+
public class Main {
13+
public static void main(String[] args) throws Exception {
14+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
15+
String A = br.readLine(), B = br.readLine();
16+
int count = A.equals(B) ? 0 : countShift(A, B);
17+
System.out.println(count > A.length() ? -1 : count);
18+
}
19+
20+
private static String rightShift(String str) {
21+
int lastIdx = str.length() - 1;
22+
return str.substring(1) + str.charAt(0);
23+
}
24+
25+
private static int countShift(String A, String B) {
26+
int count = 1;
27+
for (count = 1;count <= A.length();count++) {
28+
String newB = rightShift(B);
29+
if (A.equals(newB)) break;
30+
B = newB;
31+
}
32+
return count;
33+
}
34+
}

0 commit comments

Comments
ย (0)