Loading...
Loading...
Loading...
Some sentences are palindromes once you ignore spaces, punctuation and case, like A man, a plan, a canal: Panama. Read a sentence and print YES if its letters and digits read the same from both ends, and NO otherwise. A sentence with no letters or digits counts as a palindrome.
YES or NO.Example 1
Input
A man, a plan, a canal: Panama
Output
YES
Example 2
Input
race a car
Output
NO
raceacar is not the same reversed.
Try the problem first. Open one hint at a time.
Build a cleaned String: keep only small letters and digits after toLowerCase().
Then compare the cleaned String with its reverse, or use two indexes from both ends.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor