题目描述
思路分析
将字符串反转,后寻找到最长子串,然后用字符串长度减去最长字串长度即可。
代码实现
package lanqiao;import java.util.Scanner;public class Main {static int min=0,num=0;static String str;public static void main(String[] args) {Scanner scanner=new Scanner(System.in);str=scanner.next();min=str.length();fcode(0, min-1, 0);System.out.println(min);}public static void fcode(int left,int right,int num){if (left>=right) {min=min<num?min:num;}else {if (str.charAt(left)==str.charAt(right))fcode(left+1, right-1, num);else {fcode(left+1, right, num+1);fcode(left, right-1, num+1);}}return;}}