Problem
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.
Einschränkungen
0 ≤ length ≤ 10,000
Beispiele
Eingabe:
text = "Racecar"
Erwartete Ausgabe:
expected = True
Eingabe:
std::string text = "Racecar";
Erwartete Ausgabe:
bool expected = true;
Eingabe:
string text = "Racecar";
Erwartete Ausgabe:
bool expected = true;
Erläuterung
Lowercased, "racecar" reads the same both ways.
Eingabe:
text = "hello"
Erwartete Ausgabe:
expected = False
Eingabe:
std::string text = "hello";
Erwartete Ausgabe:
bool expected = false;
Eingabe:
string text = "hello";
Erwartete Ausgabe:
bool expected = false;
Erläuterung
"hello" backwards is "olleh", which is different.
So gehst du vor
Versuch es zuerst allein und öffne dann einen Hinweis nach dem anderen.
Hinweis 1
Ignore anything that is not a letter or digit before comparing.
Hinweis 2
Move inward from both ends, comparing case-insensitive characters.
Hinweis 3
Skip punctuation and spaces carefully so they do not break valid palindromes.
Erwartete Komplexität
O(n) time, O(1) extra space
Referenzen
Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.