Skip to content

Update Palindrome.java #665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 24, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update Palindrome.java
Test cases where String x is null or has a length of 0 or 1 for FirstWay method.
  • Loading branch information
tong72 authored Dec 23, 2018
commit a5bf69fcbd6eff2858581d07b013d79ad68fa0ce
6 changes: 4 additions & 2 deletions Others/Palindrome.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,7 +10,9 @@ private String reverseString(String x){ //*helper method


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)
Expand Down