✔ 내 답 -> 맞음
import java.util.*;
public class Main {
public static String solution(String input) {
String s = "";
input=input.replace(" ","");
// System.out.println(input);
for(int i=0;i<input.length();i++) {
if(Character.isAlphabetic(input.charAt(i))) {
s+=String.valueOf(input.charAt(i));
}
}
//System.out.println("이상한 문자 제거"+s);
s=s.toUpperCase();
char[] sarr =s.toCharArray();
int lt =0, rt=sarr.length-1;
while(lt<rt){
char tmp = sarr[lt];
sarr[lt]=sarr[rt];
sarr[rt]=tmp;
lt++;
rt--;
}
String s_rev=String.valueOf(sarr);
if(s.equals(s_rev)) return "YES";
else return "NO";
}
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
String input = kb.nextLine();
System.out.println(solution(input));
}
}
✔️ 강의 답
import java.util.*;
public class Pro8 {
public static String solution(String input) {
String answer ="NO";
input=input.toUpperCase().replaceAll("[^A~Z]","");
String tmp = new StringBuilder(input).reverse().toString();
if(input.equals(tmp)) answer="YES";
return answer;
}
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
String input = kb.next();
System.out.println(solution(input));
}
}