public class Solution {
public boolean canConstruct(String ransomNote, String magazine) {
int[] ransomNum = new int[256];
int[] magNum = new int[256];
for (int i = 0; i < 256; i++) {
ransomNum[i] = magNum[i] = 0;
}
for (int i = 0; i < ransomNote.length(); i++) {
ransomNum[(int)ransomNote.charAt(i)]++;
}
for (int i = 0; i < magazine.length(); i++) {
magNum[(int)magazine.charAt(i)]++;
}
for (int i = 0; i < 256; i++) {
if (ransomNum[i] > magNum[i]) return false;
}
return true;
}
}

LeetCode: Ransom Note的更多相关文章

  1. [LeetCode] Ransom Note 赎金条

    
Given
 an 
arbitrary
 ransom
 note
 string 
and 
another 
string 
containing 
letters from
 all 
th ...

  2. LeetCode:Ransom Note_383

    LeetCode:Ransom Note [问题再现] Given
 an 
arbitrary
 ransom
 note
 string 
and 
another 
string 
contai ...

  3. C#LeetCode刷题之#383-赎金信(Ransom Note)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3937 访问. 给定一个赎金信 (ransom) 字符串和一个杂志 ...

  4. 【LeetCode】383. Ransom Note 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 [LeetCo ...

  5. leetcode 383. Ransom Note

    
Given
 an 
arbitrary
 ransom
 note
 string 
and 
another 
string 
containing 
letters from
 all 
th ...

  6. leetcode修炼之路——383. Ransom Note

    题目是这样的 Given
 an 
arbitrary
 ransom
 note
 string 
and 
another 
string 
containing 
letters from
 a ...

  7. 14. leetcode 383. Ransom Note

    Given an arbitrary ransom note string and another string containing letters from all the magazines, ...

  8. [LeetCode&Python] Problem 383. Ransom Note

    Given an arbitrary ransom note string and another string containing letters from all the magazines, ...

  9. leetcode之Ransom Note

    题目描述: 
Given
 an 
arbitrary
 ransom
 note
 string 
and 
another 
string 
containing 
letters from
 a ...

随机推荐

  1. 跟我一起学JQuery插件开发

    http://www.cnblogs.com/Leo_wl/archive/2012/04/06/2435511.html 以前一直比较好奇,jquery插件是怎么开发的,怎么写属于自己的插件? 昨天 ...

  2. css 选择器优先级

    优先级自上而下逐渐递减 1. 在属性后面使用 !important 会覆盖页面内任何位置定义的元素样式. 2.作为style属性写在元素内的样式 3.id选择器 4.类选择器 5.标签选择器 6.通配 ...

  3. db2look和db2move详解

    db2look和db2move简单实例 --- 建库create database db_name on filesystem_location using codeset utf-8 territo ...

  4. JS运算符

    JS运算符: 使用的运算符的时候不需要声明变量,运算符非变量:1.算术运算符 + - * / % (%为取余数运算符) (自增运算符++) (自减运算符 --) + 运算符作用:1.数值相加 2.字符 ...

  5. ZeroMQ接口函数之 :zmq_plain - 明文认证

    ZeroMQ 官方地址 :http://api.zeromq.org/4-2:zmq_plain zmq_plain(7) ØMQ Manual - ØMQ/4.1.0 Name zmq_plain  ...

  6. 转:ibatis的cacheModel

    转:ibatis的cacheModel cachemodel是ibatis里面自带的缓存机制,正确的应用能很好提升我们系统的性能. 使用方法:在sqlmap的配置文件中加入 <cacheMode ...

  7. websocket 实现聊天功能

    <html> <head> <base href="<%=basePath%>"> <title>webscoket t ...

  8. 问题(the question)

    I want to know: 1. 软件开发最主要的目的 是什么? 2. 软件开发是否同样需要模,和架构? 3.软件开发与其他程序的需求分析是否相似,有什么不同之处? 4.软件开发最常用的计算机语言 ...

  9. Daily Scrum02 12.08

    编译大作业的第一次检查终于过去了,已经经过这次检查的组员们可以暂时松一口气了. 也希望编译大作业有着落的成员可以多花一些时间在团队任务上,帮其他的组员多分担一些工作. 第一次没来的及检查的同学,或是没 ...

  10. centos 安装 opencv-3.1.0

    官方安装教程 http://docs.opencv.org/3.1.0/d9/d52/tutorial_java_dev_intro.html#gsc.tab=0 注意要先安装jdk和apache a ...