본문 바로가기

Programmers/Level0

문자열 밀기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.*;
 
class Solution {
    public int solution(String A, String B) {
        int answer = 0;
        List<Character> AList = new LinkedList<>();
        for(char ch : A.toCharArray())
            AList.add(ch);
        int cnt = 0;
        for(int i=0;i<A.length();i++) {
            StringBuilder sb = new StringBuilder();
            for(char ch : AList)
                sb.append(ch);
            if(sb.toString().equals(B))
                break;
            cnt++;
            AList.add(0, AList.remove(AList.size()-1));
        }
        if(cnt == A.length())
            answer = -1;
        else
            answer = cnt;
 
        return answer;
    }
}
cs