Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,4 @@
|
|||
public static boolean pali(String testMe){
|
||||
StringBuilder sb = new StringBuilder(testMe);
|
||||
return testMe.equals(sb.reverse().toString());
|
||||
}
|
||||
19
Task/Palindrome-detection/Java/palindrome-detection-2.java
Normal file
19
Task/Palindrome-detection/Java/palindrome-detection-2.java
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
public static boolean isPalindrome(String input) {
|
||||
for (int i = 0, j = input.length() - 1; i < j; i++, j--) {
|
||||
char startChar = input.charAt(i);
|
||||
char endChar = input.charAt(j);
|
||||
|
||||
// Handle surrogate pairs in UTF-16
|
||||
if (Character.isLowSurrogate(endChar)) {
|
||||
if (startChar != input.charAt(--j)) {
|
||||
return false;
|
||||
}
|
||||
if (input.charAt(++i) != endChar) {
|
||||
return false;
|
||||
}
|
||||
} else if (startChar != endChar) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
public static boolean rPali(String testMe){
|
||||
if(testMe.length()<=1){
|
||||
return true;
|
||||
}
|
||||
if(!(testMe.charAt(0)+"").equals(testMe.charAt(testMe.length()-1)+"")){
|
||||
return false;
|
||||
}
|
||||
return rPali(testMe.substring(1, testMe.length()-1));
|
||||
}
|
||||
14
Task/Palindrome-detection/Java/palindrome-detection-4.java
Normal file
14
Task/Palindrome-detection/Java/palindrome-detection-4.java
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
public static boolean rPali(String testMe){
|
||||
int strLen = testMe.length();
|
||||
return rPaliHelp(testMe, strLen-1, strLen/2, 0);
|
||||
}
|
||||
|
||||
public static boolean rPaliHelp(String testMe, int strLen, int testLen, int index){
|
||||
if(index > testLen){
|
||||
return true;
|
||||
}
|
||||
if(testMe.charAt(index) != testMe.charAt(strLen-index)){
|
||||
return false;
|
||||
}
|
||||
return rPaliHelp(testMe, strLen, testLen, index + 1);
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
public static boolean pali(String testMe){
|
||||
return testMe.matches("|(?:(.)(?<=(?=^.*?(\\1\\2?)$).*))+(?<=(?=^\\2$).*)");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue