Site icon Wander In Dev

Valid Anagram (LeetCode #242)

Challenge Statement

Constraints

Example 1:

Input: s = "anagram", t = "nagaram"

Output: True

Example 2:

Input: s = "rat", t = "car"

Output: False

Solution

Below is my solution and some test cases. This solution has a linear time complexity O(n+n) and a linear space complexity O(n+n), where n is the length of the input string s.

Exit mobile version