Условие
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.
Ограничения
0 ≤ length ≤ 10,000
Примеры
Ввод:
text = "Racecar"
Ожидаемый вывод:
expected = True
Ввод:
std::string text = "Racecar";
Ожидаемый вывод:
bool expected = true;
Ввод:
string text = "Racecar";
Ожидаемый вывод:
bool expected = true;
Пояснение
Lowercased, "racecar" reads the same both ways.
Ввод:
text = "hello"
Ожидаемый вывод:
expected = False
Ввод:
std::string text = "hello";
Ожидаемый вывод:
bool expected = false;
Ввод:
string text = "hello";
Ожидаемый вывод:
bool expected = false;
Пояснение
"hello" backwards is "olleh", which is different.
Как подступиться
Сначала попробуйте сами, затем открывайте подсказки по одной.
Подсказка 1
Ignore anything that is not a letter or digit before comparing.
Подсказка 2
Move inward from both ends, comparing case-insensitive characters.
Подсказка 3
Skip punctuation and spaces carefully so they do not break valid palindromes.
Ожидаемая сложность
O(n) time, O(1) extra space
Ссылки
Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.