Skip to content

Commit b88e978

Browse files
author
Christian Bender
authored
Merge pull request #375 from GammaBurst101/palindrome
Resolve the conflict of closed PR #146
2 parents 4d43599 + 6f9867a commit b88e978

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Others/Palindrome.java

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

3-
public 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
@@ -9,8 +9,18 @@ public String reverseString(String x){ //*helper method
99
}
1010

1111

12-
public Boolean isPalindrome(String x){ //*palindrome method, returns true if palindrome
12+
public Boolean FirstWay(String x){ //*palindrome method, returns true if palindrome
1313
return (x.equalsIgnoreCase(reverseString(x)));
1414
}
15-
15+
16+
public boolean SecondWay(String x)
17+
{
18+
if (x.length() == 0 || x.length() == 1)
19+
return true;
20+
21+
if (x.charAt(0) != x.charAt(x.length() - 1))
22+
return false;
23+
24+
return SecondWay(x.substring(1 , x.length() - 1));
25+
}
1626
}

0 commit comments

Comments
 (0)