DEV Community

Discussion on: Reverse a Word.

Collapse
 
dallgoot profile image
dallgoot

very , very small optimization :p

public static boolean isPalindrome(String input)
{
    char[] charArray = input.toCharArray();
    int cursor = 0;
    int max = input.length() - 1;

    while(cursor <= max && charArray[cursor] == charArray[max-cursor])
    {
        cursor++;
    }
    return cursor > max; 
}

if by any chance you can benchmark the 2 versions : me very glad ;)