Ransom Note
来源:互联网 发布:医疗大数据盈利模式 编辑:程序博客网 时间:2024/06/01 08:54
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; otherwise, it will return false.
Each letter in the magazine string can only be used once in your ransom note.
var canConstruct = function(r, m) {
if(r.length > m.length) {
return false
}
if(r.length == m.length && r != m){
return false
}
var obj = {};
for(var i = 0; i < m.length; i++) {
if(!obj[m[i]]){
obj[m[i]] = 1
}else{
obj[m[i]] ++;
}
}
for(var j = 0; j < r.length; j++) {
if(obj[r[j]] && obj[r[j]] >= 0) {
obj[r[j]] -- ;
}else{
return false
}
}
return true
};
- Ransom Note
- Ransom Note
- Ransom Note
- Ransom Note
- Ransom Note
- Ransom Note
- Ransom Note
- Ransom Note
- Ransom Note
- Ransom Note
- Ransom Note
- Ransom Note
- leetcode-383. Ransom Note
- [leetcode] 383. Ransom Note
- LeetCode:383 Ransom Note
- 【Leetcode】Ransom Note
- LeetCode 383. Ransom Note
- 383. Ransom Note*
- 中缀式转后缀式
- python虚拟环境配置
- 退出一个while无限循环和多重for循环
- Android透明化/沉浸式状态栏实践及源码分析
- 第十一章练习
- Ransom Note
- 2017年4月13日读书笔记
- (转)Android ListView多种布局 getViewTypeCount和getItemViewType
- JQ判断滚动条是否到达顶部或者底部
- vue过滤器
- 关系数据理论
- 每天一个Linux命令(39):kill
- c++学习笔记--多态
- SQLSERVER清理日志