题意:给出两个字符串s1,s2 ,看s1是否可以由s2中的字符组成

具体代码如下:

public class Solution
{public boolean canConstruct(String ransomNote, String magazine){Map<Character, Integer> m = new HashMap<>();for (int i = 0; i < magazine.length(); i++) {if (m.containsKey(magazine.charAt(i))) {m.put(magazine.charAt(i), m.get(magazine.charAt(i)) + 1);} else {m.put(magazine.charAt(i), 1);}}for (int i = 0; i < ransomNote.length(); i++) {if (m.containsKey(ransomNote.charAt(i))) {int cnt = m.get(ransomNote.charAt(i));cnt--;if (cnt < 0) return false;m.put(ransomNote.charAt(i), cnt);} else {return false;}}return true;}
}

LeetCode Ransom Note(字符串)相关推荐

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

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

  2. LeetCode:383. Ransom Note

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

  3. [LeetCode] NO.383 Ransom Note

    [题目] Given
 an 
arbitrary
 ransom
 note
 string 
and 
another 
string 
containing 
letters from
 all ...

  4. Leetcode 383 Ransom Note

    lc383 Ransom Note 两个for 第一个记录sourse字符串每种字母出现次数 第二个看现有字母是否能够填满target 1 class Solution { 2 public bool ...

  5. LeetCode 383. Ransom Note

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

  6. LeetCode之Ransom Note

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

  7. C#LeetCode刷题-字符串

    字符串篇 # 题名 刷题 通过率 难度 3 无重复字符的最长子串 24.6% 中等 5 最长回文子串 22.4% 中等 6 Z字形变换 35.8% 中等 8 字符串转整数 (atoi) 15.3% 中 ...

  8. LeetCode实战:字符串相乘

    题目英文 Given two non-negative integers num1 and num2 represented as strings, return the product of num ...

  9. LeetCode实战:字符串相加

    题目英文 Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and ...

最新文章

  1. ArcEngine开发中“错误类型****未定义构造函数”
  2. argv[1] 路径问题
  3. ML之xgboost:利用xgboost算法(sklearn+GridSearchCV)训练mushroom蘑菇数据集(22+1,6513+1611)来预测蘑菇是否毒性(二分类预测)
  4. 程序猿之歌 PHP,1024丨腾讯第一首程序员之歌【Code代码】
  5. CodeForces - 932G Palindrome Partition(回文自动机+Palindrome Series优化dp)
  6. c++日志文件中文显示乱码的问题及解决办法
  7. Java Optionals获得更具表现力的代码
  8. mysql-聚合函数
  9. 《How to Generate a Good Word Embedding?》导读(转)
  10. kill-9导致weblogic无法启动
  11. 智还王项目中出现的问题和使用的一些方法
  12. python命令行参数作用_python中命令行参数和os模块常用函数
  13. Java 设计模式 Factory Method 工厂方法 模式
  14. java星空屏幕,CorelDraw 制作宇宙星空
  15. Linux那些事儿 之 戏说USB(21)向左走,向右走
  16. selenium模拟登录某宝
  17. 3060ti配什么cpu和主板
  18. 光盘或者U盘安装linux操作系统
  19. 计算机网络网络层之路由算法2链路状态路由算法
  20. 一个初中平面几何问题

热门文章

  1. jquery serialize()无效读取不到数据
  2. Quartz集成springMVC 的方案一
  3. 百度地图的立体效果来实现
  4. python语言程序设计西安电子科技大学答案-徐悦甡 | 个人信息 | 西安电子科技大学个人主页...
  5. python基础知识选择题-99道经典练习题助你全面掌握python基础知识,附技巧答案...
  6. python资料库-Python对接六大主流数据库(只需三步)
  7. python对财务人员的帮助-还不熟练VBA的财务人,让Python带你弯道超车!
  8. python下载不了-python安装不了
  9. 怎么自学python编程-零基础如何自学编程?
  10. python多个for的执行顺序-python_装饰器篇(多个装饰器下的执行顺序)