Skip to content

Commit a5bf69f

Browse files
authored
Update Palindrome.java
Test cases where String x is null or has a length of 0 or 1 for FirstWay method.
1 parent 084548d commit a5bf69f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Others/Palindrome.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class Palindrome {
22

3-
private String reverseString(String x){ //*helper method
3+
private String reverseString(String x){ //*helper method
44
String output = "";
55
for(int i=x.length()-1; i>=0; i--){
66
output += x.charAt(i); //addition of chars create String
@@ -10,7 +10,9 @@ private String reverseString(String x){ //*helper method
1010

1111

1212
public Boolean FirstWay(String x){ //*palindrome method, returns true if palindrome
13-
return (x.equalsIgnoreCase(reverseString(x)));
13+
if(x == null || x.length() <= 1)
14+
return true;
15+
return (x.equalsIgnoreCase(reverseString(x)));
1416
}
1517

1618
public boolean SecondWay(String x)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy