-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLC125.java
More file actions
28 lines (23 loc) · 748 Bytes
/
Copy pathLC125.java
File metadata and controls
28 lines (23 loc) · 748 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
class LC125 {
public static void main(String args[]) {
Solution run = new Solution();
boolean isPalindrome = run.isPalindrome("A man, a plan, a canal: Panama");
System.out.println(isPalindrome);
}
}
class Solution {
public boolean isPalindrome(String s) {
String filteredString = s.replaceAll("[^A-Za-z0-9]","");
filteredString = filteredString.toLowerCase();
System.out.println(filteredString);
int left = 0;
int right = filteredString.length() - 1;
while(left < right) {
if(filteredString.charAt(left) != filteredString.charAt(right)) return false;
left++;
right--;
}
return true;
}
}
//Solved