242. Valid Anagram

Given two stringss_and_t , write a function to determine ift_is an anagram of_s.

Example 1:

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

Output: true

Example 2:

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

Output: 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?

Thoughts:

  1. Give compare the canical sorted form

  2. Compare the char count in the map

  3. Follow-up: Method 1 would still work

Code: Sort

Code: Counting Map (elements in s and t needs to be hashable)

Last updated

Was this helpful?