150 najlepszych wywiadówŁatwe

Permutacja w ciągu

Szczegółowy przewodnik i implementacja Python dla problemu „Permutacja w łańcuchu”.

Oświadczenie o problemie

Łatwe

Biorąc pod uwagę dwa ciągi s1 i s2, zwróć True, jeśli s2 zawiera permutację s1 lub False w przeciwnym razie.

Innymi słowy, zwróć True, jeśli jedna z permutacji s1 jest podciągiem s2.

Napisz funkcję checkInclusion(s1: str, s2: str) -> bool.

Ograniczenia
  • 1 <= len(s1), len(s2) <= 10^4
  • s1 and s2 consist of lowercase English letters

Przykłady

Example 1
Input
s1 = "ab", s2 = "eidbaooo"
Output
True
Explanation

s2 contains one permutation of s1: "ba" (starting at index 3).

Example 2
Input
s1 = "ab", s2 = "eidboaoo"
Output
False
Explanation

No permutation of "ab" exists as a contiguous substring in s2.

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