Interview Question

Software Developer Intern Interview

Given a string, return true if it's a palindrome. Only

  alphanumeric characters considered. Do this in one pass through the string.
Answer

Interview Answer

1 Answer

0

boolean isPalindrome(String input) {
    String copy = input;
     for(int i = 0, j= input.length() - 1; j >= 0; --j)
           if (input.charAt(i++) != copy.charAt(j))
                 return false;
     return true;
}

KSP on Mar 2, 2013

Add Answers or Comments

To comment on this question, Sign In with Facebook or Sign Up