Einfach 0 gelöst 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.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.