383. Ransom Note
来源:互联网 发布:kk棋牌源码 编辑:程序博客网 时间:2024/05/21 10:32
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.
Note:
You may assume that both strings contain only lowercase letters.
canConstruct("a", "b") -> falsecanConstruct("aa", "ab") -> falsecanConstruct("aa", "aab") -> true
思路:
检查前面的勒索信是否可以由后面的字符串拼接而成
public boolean canConstruct(String ransomNote, String magazine) { int[] map = new int[26];for (int i = 0; i < magazine.length(); i++) {map[magazine.charAt(i) - 'a']++;}for (int i = 0; i < ransomNote.length(); i++) {if (map[ransomNote.charAt(i) - 'a'] > 0) {map[ransomNote.charAt(i) - 'a']--;} else {return false;}}return true; }
0 0
- leetcode-383. Ransom Note
- [leetcode] 383. Ransom Note
- LeetCode 383. Ransom Note
- 383. Ransom Note*
- 383. Ransom Note
- leetcode 383. Ransom Note
- leetcode 383. Ransom Note
- 383. Ransom Note
- 383.[LeetCode]Ransom Note
- 383. Ransom Note
- 383. Ransom Note【E】
- leetcode 383. Ransom Note
- 383. Ransom Note
- 383. Ransom Note
- leetcode 383. Ransom Note
- Leetcode 383. Ransom Note
- 【leetcode】383. Ransom Note
- Leetcode 383. Ransom Note
- Winform非模态对话框
- JSP学习笔记(第2次):Servlet过滤器
- 阿里云搭建的 mysql不能连接到远程或者拒绝访问解决办法
- ProgressBar设置旋转图片
- MySQL 修改字段类型或长度
- 383. Ransom Note
- fedora下载
- Run.getRuntime.exec
- 【NOIP2016提高A组模拟8.19】树上路径
- linux和qt 字符串和数字转换篇
- 从头搭建Logstash+ElasticSearch+Kibana
- windows下redis 和 hiredis的编译与使用
- bat知识点3_for循环
- 用Clonezilla再生龙备份系统分区详细教程[图文]