150 najlepszych wywiadówŁatwe

Poprawny anagram

Szczegółowy przewodnik i implementacja Python dla problemu „Prawidłowy anagram”.

Oświadczenie o problemie

Łatwe

Biorąc pod uwagę dwa ciągi s i t, zwróć True, jeśli t jest anagramem s, lub False w przeciwnym razie.

Anagram to słowo lub fraza utworzona przez zmianę układu liter innego słowa lub frazy, przy użyciu wszystkich oryginalnych liter dokładnie raz.

Napisz funkcję isAnagram(s: str, t: str) -> bool.

Ograniczenia
  • 1 <= len(s), len(t) <= 5 * 10^4
  • s and t consist of lowercase English letters

Przykłady

Example 1
Input
s = "anagram", t = "nagaram"
Output
True
Explanation

Both strings contain the same characters with the same frequencies: a(3), n(1), g(1), r(1), m(1).

Example 2
Input
s = "rat", t = "car"
Output
False
Explanation

'rat' contains 't' but 'car' does not. They have different character compositions.

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