JAVA 코딩 알고리즘 연습/프로그래머스

프로그래머스 - 문자열 밀기 / JAVA (자바) 코딩 알고리즘 연습

easpop 2023. 2. 9. 14:31
728x90
반응형

반응형
class Solution {
    public int solution(String A, String B) {
        int answer = -1;
        String copyA = "";
        String tmp = "";
        if(A.equals(B)){
            answer = 0;
        }else {
            for(int i=0; i<A.length(); i++) {
                tmp = A.substring(A.length() - 1);
                copyA = tmp + A.substring(0,A.length() - 1);
                A = copyA;

                if(A.equals(B)){
                    System.out.println(A);
                    answer = i + 1;
                }
            }
        }
        return answer;
    }
}
728x90
반응형