首页 > 技术文章 > JS Valid Anagram(leetcode 242)两个字符串包含的字符是否完全相同

bocaimao 2020-10-10 00:51 原文

Given two strings s and , write a function to determine if t is an anagram of s.

Example 1:

Input: s = "anagram", t = "nagaram"
Output: true

Example 2:

Input: s = "rat", t = "car"
Output: 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?

 1 /**
 2  * @param {string} s
 3  * @param {string} t
 4  * @return {boolean}
 5  */
 6 
 7 var isAnagram = function(s, t) {
 8     return (SortStr(s) === SortStr(t));
 9     
10 };
11 var SortStr = (str)=>{
12     console.log(str.split('').sort().join('')   )     
13 }

 

推荐阅读