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;
};

最新文章

  1. [PHP源码阅读]strpos、strstr和stripos、stristr函数
  2. UnicodeDecodeError: &#39;utf8&#39; codec can&#39;t decode byte 0xce in position 47: invalid continuation byte
  3. [Elixir008]Nested Module里的动态函数调用方式
  4. dns (域名系统)
  5. java编程acm基础
  6. stl的仿函数adapter
  7. E - Redundant Paths - poj 3177(缩点求叶子节点)
  8. ZooKeeper 实现分布式队列
  9. 第一册:Lesson 123.
  10. iOS 开发中keyChain的使用
  11. JSON.stringify 语法实例讲解+easyui data-options属性+expires【申明:来源于网络】
  12. 使用虚拟机VM12安装REHL7
  13. Clion 教程书写Hello World,C语言开发;Clion 的C语言开发
  14. 常用的代码之一:用StopWatch计算代码运行花费的时间。
  15. Tomcat7环境下面MySQL 56/Oracle数据库连接池的配置
  16. Junit进行单元测试
  17. 1059. [ZJOI2007]矩阵游戏【二分图】
  18. first-child伪类选择器
  19. 动态语言的灵活性是把双刃剑 -- 以 Python 语言为例
  20. Java反序列化漏洞之殇

热门文章

  1. 如何用Python制作优美且功能强大的数据可视化图像
  2. Mysql系列(六)—— MySQL索引介绍
  3. SQL Server中COALESCE函数的用法
  4. 一张图看懂SharpCamera
  5. 2019 边锋游戏java面试笔试题 (含面试题解析)
  6. JavaWeb分页-----PageBean.java
  7. 【转载】C#使用InsertRange方法往ArrayList集合指定位置插入另一个集合
  8. Django:RestFramework之-------分页
  9. 2007英语CET6四6级资料六级大学单词
  10. idea/借阅系统的APP开发