-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathSolution004.java
More file actions
34 lines (30 loc) · 864 Bytes
/
Solution004.java
File metadata and controls
34 lines (30 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package algorithm.alg4;
/**
* @author: mayuan
* @desc:
* @date: 2018/10/28
*/
public class Solution004 {
public static void main(String[] args) {
System.out.println("abcd 是回文字符串吗? " + isPalindrome("abcd"));
System.out.println("abcdcba 是回文字符串吗? " + isPalindrome("abcdcba"));
System.out.println("aaaa 是回文字符串吗? " + isPalindrome("aaaa"));
}
/**
* 判断字符串是否为回文字符串
*
* @param str
* @return
*/
public static boolean isPalindrome(String str) {
if (null == str || 0 == str.length()) {
return false;
}
for (int i = 0; i < str.length() / 2; ++i) {
if (str.charAt(i) != str.charAt(str.length() - 1 - i)) {
return false;
}
}
return true;
}
}