242_Valid Anagram
Question
Given two strings s and t, write a function to determine if t is an anagram of s.
What is Anagram?
- Two strings are anagram if they can be the same after change the order of characters.
For example,
s = "anagram", t = "nagaram", return true.
s = "rat", t = "car", return false.
Note:
You may assume the string contains only lowercase alphabets.
Follow up:
What if the inputs contain unicode characters? How would you adapt your solution to such case?Idea
Complexity 1
Complexity 2
Solution 1 (sort)
Solution 2 (no sort, using dictionary)
Solution 3 (no sort, using count table, same time/space complexity as solution 2)
Last updated