<span style="font-family: Arial, Helvetica, sans-serif;">package com.wzw.util;</span>
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List; public class HuiWen {
public static void main(String[] args) throws Exception
{
List<String> result=new ArrayList<String>();
String str="34554343345345";
int len=str.length();
for(int i=0;i<len-2;i++){
for(int j=i;j<len-1;j++){
StringBuffer temp=new StringBuffer(str.substring(i, j+1));
if(!(temp.toString().equals(""))){
String te=temp.toString();
String mp=temp.reverse().toString();
if(te.equals(mp)){
result.add(te);
}
}
}
}
System.out.println("全部的回文数:");
for(int i=0;i<result.size();i++){
System.out.println(result.get(i));
} System.out.println("最长的回文数是:"); int maxnum=result.toArray()[0].toString().length();
int max=0;
for(int j=0;j<result.toArray().length;j++){
if(maxnum<result.toArray()[j].toString().length()){
maxnum=result.toArray()[j].toString().length();
max = j;
}
}
System.out.println(result.toArray()[max]);
}
}

回文是对称。所以我的想法是使用一个字符串截取并比较,假设回文的记录数,然后找出最长。


[java面试题]最长的回文字符串中出现确定的更多相关文章

  1. LeetCode 第五题 最长的回文字符串 (JAVA)

    Longest Palindromic Substring 简介:字符串中最长的回文字符串 回文字符串:中心对称的字符串 ,如 mom,noon 问题详解: 给定一个字符串s,寻找字符串中最长的回文字 ...

  2. leetCode刷题(找到最长的回文字符串)

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  3. JavaScript之最长回文字符串

    JavaScript经典面试题算法:最长回文字符串 下面的解题方法是通过中心扩散法的方式实现的,具体代码和注释如下(时间复杂度: O(n^2),空间复杂度:O(1)) // str字符串functio ...

  4. [国家集训队]最长双回文串 manacher

    ---题面--- 题解: 首先有一个直观的想法,如果我们可以求出对于位置i的最长后缀回文串和最长前缀回文串,那么我们枚举分界点然后合并前缀和后缀不就可以得到答案了么? 所以我们的目标就是求出这两个数列 ...

  5. leetcode:Longest Palindromic Substring(求最大的回文字符串)

    Question:Given a string S, find the longest palindromic substring in S. You may assume that the maxi ...

  6. SRM589 DV1 250 回文字符串

    其实这道题挺简单的,不过刚开始我钻了一个错误的死胡同.想明白之后才发现. 题目要求用最少的时间来将一个字符串变成回文字符串.(具体题目参看topcoder srm589 DV1 250分值的题目,不便 ...

  7. 最长子回文字符串(Manacher’s Algorithm)

    # # 大佬博客: https://www.cnblogs.com/z360/p/6375514.html https://blog.csdn.net/zuanfengxiao/article/det ...

  8. 【LeetCode】1400. 构造 K 个回文字符串 Construct K Palindrome Strings

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 统计奇数字符出现次数 日期 题目地址:https:// ...

  9. 转载-----Java Longest Palindromic Substring(最长回文字符串)

    转载地址:https://www.cnblogs.com/clnchanpin/p/6880322.html 假设一个字符串从左向右写和从右向左写是一样的,这种字符串就叫做palindromic st ...

随机推荐

  1. Ubuntu升级到14.04

    公司网络实在太翔了,搞了一天最终成功把ubuntu从13.10升级到了14.10,中间也越到了非常多问题,记录下来,以备參考. 13.10的时候想体验一把搜狗输入法,结果因为fcitx版本号太低,用了 ...

  2. [容斥原理] zoj 3556 How Many Sets I

    主题链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=4535 How Many Sets I Time Limit: 2 ...

  3. javascript(五)验证

    <input id="domo"  type="text"> <script> function my_function(){ var ...

  4. html name id, 与服务器交互必须有name

    html name id, 与服务器交互必须有name 在HTML中元素的ID和Name的区别和联系. 今天写了个测试,在php脚本里怎么也获取不到$_POST['userName']的值,经检查在h ...

  5. 生产者、消费者 C源码,gcc编译通过

    /*生产者.消费者*/ #include<stdio.h> #include<pthread.h> #define BUFFER_SIZE 16 /***struct prod ...

  6. hdu2159 Fate 二维背包

    #include <cstring> #include <string> #include <cstdio> #include <cmath> #inc ...

  7. Keywords Search (ac 自己主动机)

    Keywords Search Problem Description In the modern time, Search engine came into the life of everybod ...

  8. 用Python对体积较大的CSV文件进行比较的经验

    用Python对体积较大的CSV文件进行比较的经验 » 进化的测试 | 进化的测试 用Python对体积较大的CSV文件进行比较的经验  python  Add comments 八 032010   ...

  9. 上mongodb创建一些吸取的经验教训指数

    想来接触mongodb它已经快一年了,对于其指数已经积累了很多的经验,知识,以这个夜黑风高的优势,放mongodb总结一番吧. 一,索引介绍 mongodb具有两类索引,分别为单键索引和复合索引. 1 ...

  10. 使用ROW_NUMBER()查询:列名 'RowNumber' 无效。

    原文:使用ROW_NUMBER()查询:列名 'RowNumber' 无效. 使用ROW_NUMBER()方法查询结果集:语句如下:   select ROW_NUMBER() OVER(ORDER ...