158.Two Strings Are Anagrams
Last updated
Was this helpful?
Last updated
Was this helpful?
Write a methodanagram(s,t)
to decide if two strings are anagrams or not.
Clarification
What is Anagram?
Two strings are anagram if they can be the same after change the order of characters.
Example
Given s ="abcd"
, t ="dcab"
, returntrue
.
Given s ="ab"
, t ="ab"
, returntrue
.
Given s ="ab"
, t ="ac"
, returnfalse
.
O(n) time, O(1) extra space
用HashMap解决