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?

/**
* @param {string} s
* @param {string} t
* @return {boolean}
*/
var isAnagram = function(s, t) { if (s == undefined || t == undefined) {
return false;
} if (s.length === 0 && t.length === t) {
return true;
} if (s.length !== t.length) {
return false;
} let hashed = {}
for (let i = 0; i < s.length; i++) {
let char = s[i];
if (char in hashed) {
hashed[char]++
} else {
hashed[char] = 1;
} let charT = t[i];
if (charT in hashed) {
hashed[charT]--;
} else {
hashed[charT] = -1;
}
} for (let value of Object.values(hashed)) {
if (value !== 0) {
return false;
}
} return true;
};

[Algorithm] 242. Valid Anagram的更多相关文章

  1. 242. Valid Anagram(C++)

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

  2. 22. leetcode 242. Valid Anagram(由颠倒字母顺序而构成的字)

    22. 242. Valid Anagram(由颠倒字母顺序而构成的字) Given two strings s and t, write a function to determine if t i ...

  3. LN : leetcode 242 Valid Anagram

    lc 242 Valid Anagram 242 Valid Anagram Given two strings s and t, write a function to determine if t ...

  4. 【LeetCode】242. Valid Anagram (2 solutions)

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

  5. [leetcode]242. Valid Anagram验证变位词

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

  6. 【LeetCode】242 - Valid Anagram

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...

  7. LeetCode 242 Valid Anagram

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

  8. 【leetcode❤python】242. Valid Anagram

    class Solution(object):    def isAnagram(self, s, t):        if sorted(list(s.lower()))==sorted(list ...

  9. 242. Valid Anagram

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...

随机推荐

  1. Replication:The transaction log for database 'tempdb' is full due to 'ACTIVE_TRANSACTION'

    今天早上,Dev跟我说,执行query statement时出现一个error,detail info是: “The transaction log for database 'tempdb' is ...

  2. Linux中历史命令

    历史命令,即之前登录session会话中的在命令行键入的命令. 在Linux中可以有两种方式查询历史命令 history命令 当前用户目录中的隐藏文件.bash_history 一.history 作 ...

  3. AQS原理解析 AbstractQueuedSynchronizer

    AQS实现原理  https://blog.csdn.net/ym123456677/article/details/80381354   https://www.cnblogs.com/keleli ...

  4. SUSE12Sp3-安装DockerCE和Docker-compose

    最近在写脚本.发现还是很方便的. Docker下载地址:https://download.docker.com/linux/static/stable/x86_64/ 执行以下脚本即可安装完毕. #! ...

  5. C:\Program不是内部或外部命令,也不是可运行的程序或批处理文件。

    问题描述:C:\Program不是内部或外部命令,也不是可运行的程序或批处理文件. 解决办法:C:\"Program Files"\具体文件目录. 具体场景:在cmd或者批处理文件 ...

  6. 无法打开内核设备:\\Global\\vmx86

    关于如题目的问题,网上有好几个解决办法,这里只介绍最方便的一个办法,利用脚本来解决 @Echo Off title Hankcs's program color 8F CD %~d0 CD %~dp0 ...

  7. axios + vue导出excel文件

    (使用到了elementUI框架) <template> <el-button type="primary" size="mini" @cli ...

  8. JS JQUERY实现滚动条自动滚到底的方法

    $(function(){ var h = $(document).height()-$(window).height(); $(document).scrollTop(h); }); \ windo ...

  9. android studio学习----调试---断点调试

    Android Studio调试其实也非常方便,一般问题直接通过AS的DDMS的Logcat就可以搞定.AS支持类似Eclipse的DDMS的所有功能.这里要说的是疑难问题的调试方式,即断点调试. 首 ...

  10. Android P(9.0) userdebug版本执行adb remount失败

    [DESCRIPTION]      在android P版本上如果按照“FAQ18076 android 6.0 M userdebug版本执行adb remount失败”的做法在userdebug ...