mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-07 01:35:16 +08:00
Resolve the conflict of #146
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
class Palindrome {
|
class Palindrome {
|
||||||
|
|
||||||
public String reverseString(String x){ //*helper method
|
private String reverseString(String x){ //*helper method
|
||||||
String output = "";
|
String output = "";
|
||||||
for(int i=x.length()-1; i>=0; i--){
|
for(int i=x.length()-1; i>=0; i--){
|
||||||
output += x.charAt(i); //addition of chars create String
|
output += x.charAt(i); //addition of chars create String
|
||||||
@ -9,8 +9,18 @@ class Palindrome {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Boolean isPalindrome(String x){ //*palindrome method, returns true if palindrome
|
public Boolean FirstWay(String x){ //*palindrome method, returns true if palindrome
|
||||||
return (x.equalsIgnoreCase(reverseString(x)));
|
return (x.equalsIgnoreCase(reverseString(x)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean SecondWay(String x)
|
||||||
|
{
|
||||||
|
if (x.length() == 0 || x.length() == 1)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (x.charAt(0) != x.charAt(x.length() - 1))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return SecondWay(x.substring(1 , x.length() - 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user