Top 150-InterviewEinfach

Palindrom-Partitionierung

Detaillierte Anleitung und Python-Implementierung für das Problem der „Palindrome-Partitionierung“.

Problemstellung

Einfach

Gegeben eine Zeichenfolge s, Partitionierung s so, dass jede Teilzeichenfolge der Partition ein Palindrom ist. Gibt alle möglichen Palindrom-Partitionierungen von s zurück.

Implementieren Sie eine Funktion partition(s: str) -> list.

Einschränkungen
  • 1 <= s.length <= 16
  • s contains only lowercase English letters

Beispiele

Example 1
Input
"aab"
Output
[["a","a","b"],["aa","b"]]
Explanation

"a","a","b" are all palindromes. "aa" is a palindrome and "b" is a palindrome. These are the only two valid partitions.

Example 2
Input
"a"
Output
[["a"]]
Explanation

A single character is always a palindrome.

Need a Hint?
Erwägen Sie die Verwendung von Backtracking-spezifischen Datenstrukturen wie Sets oder Heaps.
Edge Cases to Watch
  • Leere Eingabestrukturen
  • Einzelelementeingaben
  • Große numerische Grenzen

Bereit zur Lösung?

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

Im Editor öffnen
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

Empfohlene Python-Ressourcen

Erweitern Sie Ihr Wissen mit zugehörigen interaktiven Tutorials, Spickzetteln und Codevergleichen.