Einfach 1 gelöst 100.0% Erfolgsquote

Anagram Check

Check whether two phrases use the same letters.

Das lernst du

  • Normalize text by case and spaces
  • Compare letter counts or sorted letters
  • Choose between sorting and counting

Problem

Übersetzung anzeigen

Two phrases are anagrams if they contain exactly the same letters the same number of times, ignoring case, spaces and punctuation.

Implement is_anagram(first, second).

Input

first: The first phrase. second: The second phrase.

Output

Return true if the phrases are anagrams.

Einschränkungen

0 ≤ length of each ≤ 10,000 (ASCII)

Beispiele

Beispiel 1
Eingabe:
first = "Listen"
second = "Silent"

Erwartete Ausgabe:
expected = True
Eingabe:
std::string first = "Listen";
std::string second = "Silent";

Erwartete Ausgabe:
bool expected = true;
Eingabe:
string first = "Listen";
string second = "Silent";

Erwartete Ausgabe:
bool expected = true;

Erläuterung

Both use e, i, l, n, s, t once each.

Beispiel 2
Eingabe:
first = "apple"
second = "paddle"

Erwartete Ausgabe:
expected = False
Eingabe:
std::string first = "apple";
std::string second = "paddle";

Erwartete Ausgabe:
bool expected = false;
Eingabe:
string first = "apple";
string second = "paddle";

Erwartete Ausgabe:
bool expected = false;

Erläuterung

The letters and counts differ.

So gehst du vor

Versuch es zuerst allein und öffne dann einen Hinweis nach dem anderen.

Hinweis 1

Remove non-letters and ignore case before comparing.

Hinweis 2

Count character frequencies for both phrases, or sort their normalized forms.

Hinweis 3

Punctuation and spaces should not affect the result.

Erwartete Komplexität

O(n) time, O(1) extra space

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Die beste bestandene Lösung jedes Coders. Schnellere, sparsamere und besser bewertete Lösungen stehen weiter oben.

# Coder Sprache Zeit Speicher KI-Bewertung Lösung
1 KKKaneki Ken Python 877 ms - 4/5 Code ansehen

Von anderen lernen

Community-Lösungen

Achtung Spoiler: 1 vollständige Lösung unten Versuche es zuerst selbst zu lösen. Du kannst trotzdem einen Blick auf den Code und die KI-Reviews anderer Entwickler werfen. Melde dich an und löse die Aufgabe, um an der Diskussion teilzunehmen.