Valid Anagram
https://leetcode.com/problems/valid-anagram/description/
Given two stringssandt, write a function to determine iftis an anagram ofs.
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?
Thoughts
想法很直观。
Code
Analysis
Errors:
不能用XOR, 因为可以"aabb"和"ccdd"同样返回0.
s中元素可能比t的多
时间复杂度O(N), 空间O(1).
Last updated
Was this helpful?