判断一个字符串是否为回文,以及求一个字符串中最长回文串
2014-07-18 14:06
246 查看
<pre name="code" class="java"><pre name="code" class="java">package com.four; public class huiFe1 { public static void main(String args[]) { String str = "x1234774321sdjh"; // String str = "x212sdjh"; String result = ""; for (int i = 0; i < str.length(); i++) { result = check(result, str, i - 1, i + 1); result = check(result, str, i, i + 1); } System.out.println(result); if (result == "") { System.out.println("这不是个回文串"); } else { System.out.println(str + "中的" + result + "是一个回文"); } } public static String check(String result, String str, int start, int end) { while (start >= 0 && end < str.length()) { if (str.charAt(start) != str.charAt(end)) { break; } start--; end++; } start++; end--; if (start != end) { String temp = str.substring(start, end + 1); if (temp.length() > result.length()) { result = temp; } } return result; } }
相关文章推荐
- 判断一个字符串是否回文?
- 简单递归____判断一个字符串是否为回文
- 判断一个字符串通过变化字符的位置,是否可以组成回文
- Valid Palindrome 判断一个字符串是否是回文串
- 判断一个字符串是否为回文的非递归算法
- php學習 --- 调节器 以及如何判断一个字符串是否是邮件
- C#--第2周实验--任务7--编写一个控制台应用--判断S所指的字符串是否回文(即顺读和逆读相同的字符串)
- PHP判断一个字符串是否是回文字符串的方法
- 判断一个字符串是否是“回文”数字
- 判断一个字符串是否为回文的递归算法
- 队列-----判断一个字符串是否是回文
- 使用bool函数判断一个字符串是否为回文字符串
- C++常考的上机题型:判断一个字符串是否为回文串(递归实现)
- 判断一个字符串是否为回文
- 判断一个字符串是否为回文
- 判断一个字符串是否为回文
- 设计一个算法判断一个字符串是否是回文
- 判断一个字符串是否为回文(递归)
- 判断一个字符串是否为回文的非递归算法
- 判断一个字符串在至多删除k个字符后是否为回文串