:orphan: Valid Anagram ============= .. highlight:: none Problem ------- https://leetcode.com/problems/valid-anagram/ Given two strings ``s`` and ``t``, return ``true`` if ``t`` is an anagram of ``s``, and ``false`` otherwise.   **Example 1:** .. container:: example-block **Input:** s = "anagram", t = "nagaram" **Output:** true **Example 2:** .. container:: example-block **Input:** s = "rat", t = "car" **Output:** false   **Constraints:** - ``1 <= s.length, t.length <= 5 * 10``\ :sup:```4``` - ``s`` and ``t`` consist of lowercase English letters.   **Follow up:** What if the inputs contain Unicode characters? How would you adapt your solution to such a case? .. highlight:: python Pattern ------- Hash Table, String, Sorting Solution -------- For two strings to be anagrams, they must have the same number of each character. We can track the occurrences of each character in a dictionary, incrementing for ``s`` and decrementing for ``t``. If the dictionary only contanins 0's, then ``s`` and ``t`` are anagrams. Code ---- .. literalinclude:: ../problems/easy/valid-anagram/valid_anagram__approach_1.py :language: python :lines: 10- Test ---- >>> from valid_anagram__approach_1 import isAnagram >>> isAnagram('anagram', 'nagaram') True >>> isAnagram('rat', 'car') False Complexity ---------- | :math:`n` is the length of ``s`` and ``t``. | Time: :math:`O(n)` — count characters in ``s`` and ``t`` | Auxiliary Space: :math:`O(1)` — dictionary size bounded by character set (26 lowercase letters) .. autofunction:: valid_anagram__approach_1.isAnagram