From 6f9867a7656283b5f300a8b142d868719a5235ae Mon Sep 17 00:00:00 2001 From: Prasoon Date: Sat, 3 Feb 2018 11:44:46 +0530 Subject: [PATCH] Resolve the conflict of #146 --- Others/Palindrome.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Others/Palindrome.java b/Others/Palindrome.java index 6017f0880a61..0bbddb7544c8 100644 --- a/Others/Palindrome.java +++ b/Others/Palindrome.java @@ -1,6 +1,6 @@ class Palindrome { - public 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 @@ -9,8 +9,18 @@ public String reverseString(String x){ //*helper method } - public Boolean isPalindrome(String x){ //*palindrome method, returns true if palindrome + public Boolean FirstWay(String x){ //*palindrome method, returns true if palindrome return (x.equalsIgnoreCase(reverseString(x))); } - + + public boolean SecondWay(String x) + { + if (x.length() == 0 || x.length() == 1) + return true; + + if (x.charAt(0) != x.charAt(x.length() - 1)) + return false; + + return SecondWay(x.substring(1 , x.length() - 1)); + } }