Problem
Given two strings s and t , write a function to determine if t is an anagram of s.
Example 1:
1 | Input: s = "anagram", t = "nagaram" |
Example 2:
1 | Input: s = "rat", t = "car" |
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?
Analysis
题目给出两个词语,要求判断这两个是否同字母异序词。和之前有一道题目非常类似,主要判断三个条件:
- 长度是否相等;
- 组成的元素是否相同;
- 每个元素出现的次数是否相同。
Solution
上面的三个条件中,第一个很容易判断,第二个和第三个就需要用一个数组来统计。
Code
1 | class Solution { |
Summary
这道题目的分享到这里,谢谢您的支持!