Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a5bf69f

Browse filesBrowse 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
Copy full SHA for a5bf69f

File tree

Expand file treeCollapse file tree

1 file changed

+4
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+4
-2
lines changed
Open diff view settings
Collapse file

‎Others/Palindrome.java‎

Copy file name to clipboardExpand all lines: Others/Palindrome.java
+4-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.