One of classic problem - easy to solve.
Given a string, need to check if this string a palindrome?
The key is to create two methods - using "one method - one responsibility approach": to validate the String and to reverse the String.
public class Solution { private static boolean isPalindrome(String str) { if (str.equals(reverseString(str)){
return true;
}
return false; }
private static String reverseString(String str){
return (new StringBuilder(str)).reverse().toString();
} }
Memory O(n)Steps: O(n) - linear