题解 | #统计回文#
统计回文
https://www.nowcoder.com/practice/9d1559511b3849deaa71b576fa7009dc
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int count = 0; StringBuilder s = new StringBuilder(sc.nextLine()); String m = sc.nextLine(); for (int i = 0; i <= s.length(); i++) { StringBuilder n = new StringBuilder(s); n.insert(i, m); if (isLegal(n)) { count++; } } System.out.println(count); } private static boolean isLegal(StringBuilder n) { boolean flag = true; for (int i = 0; i < n.length() / 2; i++) { if (n.charAt(i) == n.charAt(n.length() - 1 - i)) { flag = true; } else { flag = false; break; } } return flag; } }