import java.util.*;
public class rearrange_palindrome {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String st=sc.nextLine();
ArrayList<Character> ar = new ArrayList<Character>();
for (int i=0;i<st.length();i++){
if (ar.contains(st.charAt(i)))
ar.remove((Character)st.charAt(i));//why did they use type casting?
else
ar.add(st.charAt(i));
}
if (st.length()%2==0 && ar.isEmpty()==true || st.length()%2==1 && ar.size()==1)
System.out.println("Palindrome");
else
System.out.println("Not a palindrome");
}
}
Run Code Online (Sandbox Code Playgroud)
请告诉我他们为什么使用类型转换的原因,我已经评论了该行。