File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11class 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 }
You can’t perform that action at this time.
0 commit comments