* 判断是不是对称串
* 将字符进栈,然后扫描字符串和出栈的是否相同
*
public class SymmetricString {
public static void main(String[] args) {
String s ="mnaanm";
String s1 = "1234321";
String s2 ="15553153";
System.out.println(isSymmetric(s));
System.out.println(isSymmetric(s1));
System.out.println(isSymmetric(s2));
}
public static boolean isSymmetric(String s) {
char[] ch =s.toCharArray();
int i =0;
int j= ch.length-1;
while(ch[i++]==ch[j--]){
if(ch[i]!=ch[j]) {
return false;
}
if(i>=j) {
return true;
}
}
return false;
}
}
打开App,阅读手记