Valid Anagram
You get two words, s and t. Find out whether the letters of s can be rearranged to make t. Our example: "secure" and "rescue" — yes, both have the same letters, two e's included.
- input
s,t: strings.- returns
trueiftis an anagram ofs: the same letters, each as many times, in any order; otherwisefalse.- constraints
- 1 ≤ s.length, t.length ≤ 2000
- s, t: lowercase English letters
- examples
- Open a test in the tests panel: it shows the input and the expected answer.
/**
* @param {string} s
* @param {string} t
* @return {boolean}
*/
function isAnagram(s, t) {
}
Ctrl ↵
format
reset
saved in this browser
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more hash map problems
- 1Two SumEasysolve
- 217Contains DuplicateEasysolve
- 169Majority ElementEasysolve
- 383Ransom NoteEasysolve
- 205Isomorphic StringsEasysolve
- 290Word PatternEasysolve
- 219Contains Duplicate IIEasysolve
- 49Group AnagramsMediumsolve
- 128Longest Consecutive SequenceMediumsolve
- 36Valid SudokuMediumsolve
- 138Copy List with Random PointerMediumsolve
- 149Max Points on a LineHardsolve
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.