java 求最长回文子串

来源:互联网 发布:淘宝新开店铺采集 编辑:程序博客网 时间:2024/06/05 20:28

/**     * 求最长回文子串     * 子串:连续的     * 暴力穷举     */    public static String get01() {        String str = "googlepppe";        int length = str.length();        String finalStr = "";        for (int start = 0; start < length; start++) {            for (int end = start + 1; end <= length; end++) {                String temp = str.substring(start, end);                if (temp != null) {                    if (temp.length() > finalStr.length() && isMirror(temp)) {                        finalStr = temp;                    }                }            }        }        Log.i("test","finalStr="+finalStr);        return finalStr;    }    public static boolean isMirror(String str){        for (int i = 0; i < str.length(); i++) {            if(str.charAt(i) != str.charAt(str.length()-i-1)){                return false;            }        }        return true;    }}

方法比较傻,还有别的方法,待续

0 0
原创粉丝点击