Valid Anagram
Given two strings s
and t
, return true
if t
is an anagram of s
, and false
otherwise.
An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
Example 1:
1 | Input: s = "anagram", t = "nagaram" |
Example 2:
1 | Input: s = "rat", t = "car" |
排序法:
时间复杂度:O(nlogn)
空间复杂度:O(logn)
1 | class Solution { |
哈希表:
时间复杂度:O(n)
空间复杂度:O(s),s为字符集大小
1 | class Solution { |