Einfach 0 gelöst 0% Erfolgsquote

Palindrome String

Check whether text reads the same forwards and backwards.

Das lernst du

  • Compare characters from both ends
  • Stop early when a mismatch appears
  • Handle empty and one-character strings

Problem

Übersetzung anzeigen

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

Beispiel 1
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.

Beispiel 2
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.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.