New answers tagged

1

A common problem for "western" programmers is the inability to process letters that consist of multiple characters. Your approach will fail if it encounters one of those. Unfortunately, the String class does not contain a reverse operation so once you have stripped the original string from punctuation and whitespace and converted it to upper or lower case, ...


2

boolean palindrome = true; While there are some who swear by this formulation, I find it just makes things more complicated. You don't need a variable to track whether it is a palindrome. If you find a pair of letters that don't match, you can return false immediately. If your method is so long that this is confusing, then it should probably be broken ...


3

Your basic approach looks good. However I noticed a few things: You're not checking for strings with 0 characters. The ternary statement adjusting for odd or even length is unnecessary. Simply dividing by 2 and adding 1 will work for both odd or even lengths. Inside the loop, you're calling toLower() twice on each iteration. This is quite inefficient. ...


Top 50 recent answers are included