150 najlepszych wywiadówŁatwe

Prawidłowy Palindrom

Szczegółowy przewodnik i implementacja Python dla problemu „prawidłowego palindromu”.

Oświadczenie o problemie

Łatwe

Wyrażenie jest palindromem, jeśli po zamianie wszystkich wielkich liter na małe i usunięciu wszystkich znaków innych niż alfanumeryczne, czyta się je tak samo od przodu i od tyłu. Znaki alfanumeryczne obejmują litery i cyfry.

Biorąc pod uwagę ciąg s, zwróć True, jeśli jest to palindrom, lub False w przeciwnym razie.

Napisz funkcję isPalindrome(s: str) -> bool.

Ograniczenia
  • 1 <= len(s) <= 2 * 10^5
  • s consists only of printable ASCII characters

Przykłady

Example 1
Input
s = "A man, a plan, a canal: Panama"
Output
True
Explanation

After removing non-alphanumeric characters and converting to lowercase: "amanaplanacanalpanama", which is a palindrome.

Example 2
Input
s = "race a car"
Output
False
Explanation

After processing: "raceacar" is not a palindrome.

Example 3
Input
s = " "
Output
True
Explanation

After removing non-alphanumeric characters, s is an empty string. An empty string is a palindrome by definition.

Need a Hint?
Rozważ użycie struktur danych specyficznych dla dwóch wskaźników, takich jak zestawy lub sterty.
Edge Cases to Watch
  • Puste struktury wejściowe
  • Wejścia jednoelementowe
  • Duże granice liczbowe

Gotowy do rozwiązania?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Otwórz w Edytorze
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Polecane zasoby Pythona

Poszerzaj swoją wiedzę dzięki powiązanym interaktywnym samouczkom, ściągawkom i porównaniom kodów.