펠린드롬만들기

황상익·2024년 1월 1일
0

백준

목록 보기
14/15

import java.util.Scanner;

public class 팰린드롬만들기 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String s = sc.nextLine();
        int n = s.length();

        for (int i = 0; i < s.length(); i++) {
            if (isPalindrome(s.substring(i))){
                break;
            }
            n++;
        }
        System.out.println(n);
    }

    public static boolean isPalindrome(String s){
        int start = 0;
        int end = s.length() - 1;

        while (start <= end){
            if (s.charAt(start) != s.charAt(end)){
                return false;
            }
            start++;
            end--;
        }
        return true;
    }
}
profile
개발자를 향해 가는 중입니다~! 항상 겸손

0개의 댓글