https://leetcode.com/problems/ransom-note/

public class Solution {
public boolean canConstruct(String ransomNote, String magazine) {
char[] chRan = ransomNote.toCharArray();
char[] chMag = magazine.toCharArray();
Arrays.sort(chRan);
Arrays.sort(chMag);
int j = 0;
for (int i=0; i<chRan.length; i++) {
for (; j<chMag.length; j++) {
if (chMag[j] > chRan[i]) {
return false;
}
if (chMag[j] == chRan[i]) {
break;
}
}
if (j < chMag.length) {
j++;
}
else {
return false;
}
}
return true;
}
}

ransom-note的更多相关文章

  1. [LeetCode] Ransom Note 赎金条

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

  2. leetcode 383. Ransom Note

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

  3. 383. Ransom Note

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

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

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

  5. 14. leetcode 383. Ransom Note

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

  6. Ransom Note(383)

    题目:Given an arbitrary ransom note string and another string containing letters from all the magazine ...

  7. [Swift]LeetCode383. 赎金信 | 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 ...

  10. Java [Leetcode 383]Ransom Note

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

随机推荐

  1. MDP中值函数的求解

    MDP概述   马尔科夫决策过程(Markov Decision Process)是强化学习(reinforcement learning)最基本的模型框架.它对序列化的决策过程做了很多限制.比如状态 ...

  2. Redis和MySQL数据一致中出现的几种情况

    1. MySQL持久化数据,Redis只读数据 redis在启动之后,从数据库加载数据. 读请求: 不要求强一致性的读请求,走redis,要求强一致性的直接从mysql读取 写请求: 数据首先都写到数 ...

  3. 概率论中常见分布总结以及python的scipy库使用:两点分布、二项分布、几何分布、泊松分布、均匀分布、指数分布、正态分布

    概率分布有两种类型:离散(discrete)概率分布和连续(continuous)概率分布. 离散概率分布也称为概率质量函数(probability mass function).离散概率分布的例子有 ...

  4. 韩梦飞沙Android应用集合 想法

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 那些收藏的图片 那些收藏的微博 那些收藏的音乐 定时短信 音乐列表汇 每天都是快乐的

  5. JMS异步消息机制

    企业消息系统 Java Message Service 是由 Sun Microsystems 开发的,它为 Java 程序提供一种访问 企业消息系统 的方法.在讨论 JMS 之前,我们分来析一下企业 ...

  6. 渗透测试中的bypass技巧

    0x00 前言 许多朋友在渗透测试中因为遇到WAF而束手无策,本人应邀,与godkiller一同写下此文,希望能够对许多朋友的问题有所帮助. 此系列一共分为五篇文章,分别如下: 一.架构层绕过WAF ...

  7. [CodeVS1243]网络提速

    题目大意: 有n个点的连通图,有m次可以将某一条边权值减半的机会. 不同的机会可以叠加作用于同一条边. 求1~n的最短路. 思路: 拆点,记录1到每个点在使用不同次数的机会后的最短路,然后直接跑Dij ...

  8. eclipse转idea, 快捷键设置

    设置快捷键的途径: 打开idea的配置,找到Keymap,设置为eclipse 另外还要手动设置某些快捷键 上下移动 点击类打开 代码提示 查询 重命名 快速实现接口 回到上一次光标处

  9. Codeforces Round #298 (Div. 2) C. Polycarpus' Dice 数学

    C. Polycarpus' Dice Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/534/p ...

  10. 证明 O(n/1+n/2+…+n/n)=O(nlogn)

    前言 在算法中,经常需要用到一种与调和级数有关的方法求解,在分析该方法的复杂度时,我们会经常得到\(O(\frac{n}{1}+\frac{n}{2}+\ldots+\frac{n}{n})\)的复杂 ...