forked from anthonynsimon/java-ds-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPalindromeChecker.java
More file actions
30 lines (22 loc) · 842 Bytes
/
PalindromeChecker.java
File metadata and controls
30 lines (22 loc) · 842 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
package com.anthonynsimon.algorithms.strings;
public final class PalindromeChecker {
public static boolean isPalindrome(String str) {
int strLength = str.length();
for (int i = 0; i < strLength / 2; i++) {
if (str.charAt(i) != str.charAt(strLength - 1 - i)) {
return false;
}
}
return true;
}
public static boolean isPalindrome(String str, char[] omittableChars) {
Sanitizer sanitizer = new Sanitizer();
str = sanitizer.sanitize(str, omittableChars);
return isPalindrome(str);
}
public static boolean isPalindromeIgnoreCase(String str, char[] omittableChars) {
Sanitizer sanitizer = new Sanitizer();
str = sanitizer.sanitize(str, omittableChars);
return isPalindrome(str.toLowerCase());
}
}