242. Valid Anagram

Leetcode

https://leetcode.com/problems/valid-anagram/arrow-up-right

題目

Given two strings s and t, return true if t is an anagram of s, and false otherwise.

解答

  • 方法一

var isAnagram = function(s, t) {
    if(s.length != t.length) return false;

    s = s.split("").sort().join("");
    t = t.split("").sort().join("");

    return s == t;
};

Runtime: 188 ms, faster than 9.30% of JavaScript online submissions for Valid Anagram.

Memory Usage: 44.7 MB, less than 22.52% of JavaScript online submissions for Valid Anagram.

  • 方法二

Runtime: 117 ms, faster than 41.56% of JavaScript online submissions for Valid Anagram.

Memory Usage: 39.6 MB, less than 97.20% of JavaScript online submissions for Valid Anagram.

測資

Last updated