mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-07 17:56:02 +08:00
Update Palindrome.java
Test cases where String x is null or has a length of 0 or 1 for FirstWay method.
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
class Palindrome {
|
||||
|
||||
private String reverseString(String x){ //*helper method
|
||||
private String reverseString(String x){ //*helper method
|
||||
String output = "";
|
||||
for(int i=x.length()-1; i>=0; i--){
|
||||
output += x.charAt(i); //addition of chars create String
|
||||
@ -10,7 +10,9 @@ class Palindrome {
|
||||
|
||||
|
||||
public Boolean FirstWay(String x){ //*palindrome method, returns true if palindrome
|
||||
return (x.equalsIgnoreCase(reverseString(x)));
|
||||
if(x == null || x.length() <= 1)
|
||||
return true;
|
||||
return (x.equalsIgnoreCase(reverseString(x)));
|
||||
}
|
||||
|
||||
public boolean SecondWay(String x)
|
||||
|
Reference in New Issue
Block a user