-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path125_Valid_Palindrome.java
More file actions
49 lines (31 loc) · 1.1 KB
/
125_Valid_Palindrome.java
File metadata and controls
49 lines (31 loc) · 1.1 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*Author: Bochen (mddboc@foxmail.com)
Last Modified: Tue Apr 10 22:28:44 CST 2018*/
/*Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
"A man, a plan, a canal: Panama" is a palindrome.
"race a car" is not a palindrome.
Note:
Have you consider that the string might be empty? This is a good question to ask during an interview.
For the purpose of this problem, we define empty string as valid palindrome.*/
import java.lang.System;
public class Main
{
public static void main(String[] args)
{
String string = "ab";
Solution solution = new Solution();
boolean receiveFlag = solution.isPalindrome(string);
System.out.println(receiveFlag);
}
}
class Solution {
public boolean isPalindrome(String s) {
if (s.isEmpty())
{
return true;
}
s = s.toLowerCase().replaceAll("[^a-z0-9]", "");
String reverseS = new StringBuilder(s).reverse().toString();
return (s.equals(reverseS));
}
}