Problem
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
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.
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.