LeetCode Ransom Note(字符串)
题意:给出两个字符串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(字符串)相关推荐
- C#LeetCode刷题之#383-赎金信(Ransom Note)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3937 访问. 给定一个赎金信 (ransom) 字符串和一个杂志 ...
- LeetCode:383. Ransom Note
051104 题目 Given an arbitrary ransom note string and another string containing letters from all the m ...
- [LeetCode] NO.383 Ransom Note
[题目] Given an arbitrary ransom note string and another string containing letters from all ...
- Leetcode 383 Ransom Note
lc383 Ransom Note 两个for 第一个记录sourse字符串每种字母出现次数 第二个看现有字母是否能够填满target 1 class Solution { 2 public bool ...
- LeetCode 383. Ransom Note
题目 : Given an arbitrary ransom note string and another string containing letters from all the magazi ...
- LeetCode之Ransom Note
1.题目 Given an arbitrary ransom note string and another string containing letters from all the magazi ...
- C#LeetCode刷题-字符串
字符串篇 # 题名 刷题 通过率 难度 3 无重复字符的最长子串 24.6% 中等 5 最长回文子串 22.4% 中等 6 Z字形变换 35.8% 中等 8 字符串转整数 (atoi) 15.3% 中 ...
- LeetCode实战:字符串相乘
题目英文 Given two non-negative integers num1 and num2 represented as strings, return the product of num ...
- LeetCode实战:字符串相加
题目英文 Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and ...
最新文章
- ArcEngine开发中“错误类型****未定义构造函数”
- argv[1] 路径问题
- ML之xgboost:利用xgboost算法(sklearn+GridSearchCV)训练mushroom蘑菇数据集(22+1,6513+1611)来预测蘑菇是否毒性(二分类预测)
- 程序猿之歌 PHP,1024丨腾讯第一首程序员之歌【Code代码】
- CodeForces - 932G Palindrome Partition(回文自动机+Palindrome Series优化dp)
- c++日志文件中文显示乱码的问题及解决办法
- Java Optionals获得更具表现力的代码
- mysql-聚合函数
- 《How to Generate a Good Word Embedding?》导读(转)
- kill-9导致weblogic无法启动
- 智还王项目中出现的问题和使用的一些方法
- python命令行参数作用_python中命令行参数和os模块常用函数
- Java 设计模式 Factory Method 工厂方法 模式
- java星空屏幕,CorelDraw 制作宇宙星空
- Linux那些事儿 之 戏说USB(21)向左走,向右走
- selenium模拟登录某宝
- 3060ti配什么cpu和主板
- 光盘或者U盘安装linux操作系统
- 计算机网络网络层之路由算法2链路状态路由算法
- 一个初中平面几何问题
热门文章
- jquery serialize()无效读取不到数据
- Quartz集成springMVC 的方案一
- 百度地图的立体效果来实现
- python语言程序设计西安电子科技大学答案-徐悦甡 | 个人信息 | 西安电子科技大学个人主页...
- python基础知识选择题-99道经典练习题助你全面掌握python基础知识,附技巧答案...
- python资料库-Python对接六大主流数据库(只需三步)
- python对财务人员的帮助-还不熟练VBA的财务人,让Python带你弯道超车!
- python下载不了-python安装不了
- 怎么自学python编程-零基础如何自学编程?
- python多个for的执行顺序-python_装饰器篇(多个装饰器下的执行顺序)