用递归的方法,判断回文字符串
2010-07-31 11:17
225 查看
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;
mso-font-charset:0;
mso-generic-font-family:roman;
mso-font-pitch:variable;
mso-font-signature:-1610611985 1107304683 0 0 159 0;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:-1610611985 1073750139 0 0 159 0;}
@font-face
{font-family:"/@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-font-family:宋体;
mso-bidi-font-family:"Times New Roman";
mso-font-kerning:1.0pt;}
.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
font-size:10.0pt;
mso-ansi-font-size:10.0pt;
mso-bidi-font-size:10.0pt;
mso-ascii-font-family:Calibri;
mso-fareast-font-family:宋体;
mso-hansi-font-family:Calibri;
mso-font-kerning:0pt;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.WordSection1
{page:WordSection1;}
-->
public
class
Palindrome {
public
static
void
main(String[] args) {
String arr[] = {
"abcdcba"
,
"abccba"
,
"abccbas"
,
"abcdacba"
};
for
(
int
i = 0; i < arr.
length
; i++) {
System.
out
.println(arr[i] +
" = "
+ isPalindrome
(arr[i].trim()));
}
}
public
static
boolean
isPalindrome(String str) {
int
len = str.length();
if
(
null
== str || len < 1)
return
false
;
char
a = str.charAt(0);
char
b = str.charAt(len - 1);
if
(a != b)
return
false
;
if
(2 == len || 1 == len)
return
true
;
return
isPalindrome
(str.substring(1, len - 1).trim());
}
}
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;
mso-font-charset:0;
mso-generic-font-family:roman;
mso-font-pitch:variable;
mso-font-signature:-1610611985 1107304683 0 0 159 0;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:-1610611985 1073750139 0 0 159 0;}
@font-face
{font-family:"/@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-font-family:宋体;
mso-bidi-font-family:"Times New Roman";
mso-font-kerning:1.0pt;}
.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
font-size:10.0pt;
mso-ansi-font-size:10.0pt;
mso-bidi-font-size:10.0pt;
mso-ascii-font-family:Calibri;
mso-fareast-font-family:宋体;
mso-hansi-font-family:Calibri;
mso-font-kerning:0pt;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:36.0pt;
mso-footer-margin:36.0pt;
mso-paper-source:0;}
div.WordSection1
{page:WordSection1;}
-->
public
class
Palindrome {
public
static
void
main(String[] args) {
String arr[] = {
"abcdcba"
,
"abccba"
,
"abccbas"
,
"abcdacba"
};
for
(
int
i = 0; i < arr.
length
; i++) {
System.
out
.println(arr[i] +
" = "
+ isPalindrome
(arr[i].trim()));
}
}
public
static
boolean
isPalindrome(String str) {
int
len = str.length();
if
(
null
== str || len < 1)
return
false
;
char
a = str.charAt(0);
char
b = str.charAt(len - 1);
if
(a != b)
return
false
;
if
(2 == len || 1 == len)
return
true
;
return
isPalindrome
(str.substring(1, len - 1).trim());
}
}
相关文章推荐
- 递归方法判断数组是否为递增数组
- 递归方法判断数组中的元素是否有序(Java实现)
- 【代码重构 & JDT】判断一个方法是否是实现重写,继承重写和递归
- 用递归的方法判断整数组a[N]是不是升序排列
- 用递归实现判断一个字符串是否是回文的方法
- 用递归的方法判断整数组a[N]是不是升序排列
- leetcode_101. Symmetric Tree 对称树, 判断一棵二叉树是否对称,递归方法
- 95 1.判断一字符串是不是对称 2.用递归的方法判断整数组 a[N]是不是升序排列
- 用递归的方法,判断某个字符串是否为回文
- 用递归方法判断两棵树是否相等
- PHP判断文件夹是否存在和创建文件夹的方法(递归创建多级目录)
- 用递归实现判断一个字符串是否是回文的方法
- 判断整形数组是按升序还是降序排列的,采用递归的方法
- 用递归的方法判断整数组a[N]是不是升序排列
- 华为面试题:用递归的方法判断整数组a[N]是不是升序排列
- 用递归判断回文字符串
- 链表有环判断,快慢指针两种方法/合并链表/删除重复元素/二分递归和while
- Leetcode 101. Symmetric Tree 判断二叉树是否对称,注意写在两个方法中,递归时注意空的判断
- 用递归的方法判断一个数组是否为递增数组
- 递归算法深入浅出四:递归判断回文串以及递归辅助方法