Python PodstawyŁatwe

Partycje palindromiczne

Szczegółowy przewodnik i implementacja Python dla problemu „Partycje palindromiczne”.

Oświadczenie o problemie

Łatwe

Napisz funkcję palindromic_partitions(s), która zwraca wszystkie możliwe sposoby podziału łańcucha s w taki sposób, że każdy podciąg w partycji jest palindromem. Zwraca posortowaną listę partycji, gdzie każda partycja jest listą ciągów. Sortuj, porównując leksykograficznie partycje.

Ograniczenia
  • 1 <= len(s) <= 16
  • s contains only lowercase English letters

Przykłady

Example 1
Input
s = 'aab'
Output
[['a', 'a', 'b'], ['aa', 'b']]
Explanation

'a','a','b' are all palindromes. 'aa' is a palindrome and 'b' is a palindrome. 'aab' itself is not a palindrome.

Example 2
Input
s = 'a'
Output
[['a']]
Explanation

A single character is always a palindrome.

Example 3
Input
s = 'aba'
Output
[['a', 'b', 'a'], ['aba']]
Explanation

Both ['a','b','a'] and ['aba'] consist of only palindromic substrings.

Need a Hint?
Rozważ użycie struktur danych specyficznych dla rekurencji, 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.