Problema
Decide whether text is a palindrome, considering only letters and digits and ignoring case.
Implement is_palindrome(text).
Input
text: The text to check (ASCII characters).
Output
Return true for a palindrome, otherwise false.
Vincoli
0 ≤ length ≤ 10,000
Esempi
Input:
text = "Racecar"
Output atteso:
expected = True
Input:
std::string text = "Racecar";
Output atteso:
bool expected = true;
Input:
string text = "Racecar";
Output atteso:
bool expected = true;
Spiegazione
Lowercased, "racecar" reads the same both ways.
Input:
text = "hello"
Output atteso:
expected = False
Input:
std::string text = "hello";
Output atteso:
bool expected = false;
Input:
string text = "hello";
Output atteso:
bool expected = false;
Spiegazione
"hello" backwards is "olleh", which is different.
Come affrontarlo
Prova prima da solo, poi apri un suggerimento alla volta.
Suggerimento 1
Ignore anything that is not a letter or digit before comparing.
Suggerimento 2
Move inward from both ends, comparing case-insensitive characters.
Suggerimento 3
Skip punctuation and spaces carefully so they do not break valid palindromes.
Complessità attesa
O(n) time, O(1) extra space
Riferimenti
Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.