File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 1
1
class Palindrome {
2
2
3
- public String reverseString (String x ){ //*helper method
3
+ private String reverseString (String x ){ //*helper method
4
4
String output = "" ;
5
5
for (int i =x .length ()-1 ; i >=0 ; i --){
6
6
output += x .charAt (i ); //addition of chars create String
@@ -9,8 +9,18 @@ public String reverseString(String x){ //*helper method
9
9
}
10
10
11
11
12
- public Boolean isPalindrome (String x ){ //*palindrome method, returns true if palindrome
12
+ public Boolean FirstWay (String x ){ //*palindrome method, returns true if palindrome
13
13
return (x .equalsIgnoreCase (reverseString (x )));
14
14
}
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
+ }
16
26
}
You can’t perform that action at this time.
0 commit comments