Легко Решена: 1 Процент решений: 100.0%

Anagram Check

Check whether two phrases use the same letters.

Чему вы научитесь

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

Условие

Показать перевод

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.

Ограничения

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

Примеры

Пример 1
Ввод:
first = "Listen"
second = "Silent"

Ожидаемый вывод:
expected = True
Ввод:
std::string first = "Listen";
std::string second = "Silent";

Ожидаемый вывод:
bool expected = true;
Ввод:
string first = "Listen";
string second = "Silent";

Ожидаемый вывод:
bool expected = true;

Пояснение

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

Пример 2
Ввод:
first = "apple"
second = "paddle"

Ожидаемый вывод:
expected = False
Ввод:
std::string first = "apple";
std::string second = "paddle";

Ожидаемый вывод:
bool expected = false;
Ввод:
string first = "apple";
string second = "paddle";

Ожидаемый вывод:
bool expected = false;

Пояснение

The letters and counts differ.

Как подступиться

Сначала попробуйте сами, затем открывайте подсказки по одной.

Подсказка 1

Remove non-letters and ignore case before comparing.

Подсказка 2

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

Подсказка 3

Punctuation and spaces should not affect the result.

Ожидаемая сложность

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

Ссылки

Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.

Лучшее принятое решение каждого участника. Более быстрые, экономные и высоко оценённые решения стоят выше.

# Участник Язык Время Память Оценка ИИ Решение
1 KKKaneki Ken Python 877 ms - 4/5 Посмотреть код

Учитесь у других

Решения сообщества

Внимание, спойлер: ниже 1 полное решение Попробуйте сначала решить сами. Вы всегда можете посмотреть код других и AI-обзоры. Войдите и решите задание, чтобы присоединиться к обсуждению.