【LeetCode】 383. Ransom Note
来源:互联网 发布:约翰 巴丁 知乎 编辑:程序博客网 时间:2024/05/01 01:45
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 class Solution { public boolean canConstruct(String ransomNote, String magazine) { int[] charArray = new int[26]; for (char c : magazine.toCharArray()) { charArray[c - 'a']++; } for (char c : ransomNote.toCharArray()) { if (--charArray[c - 'a'] < 0) { return false; } } return true; }}
0 0
- leetcode-383. Ransom Note
- [leetcode] 383. Ransom Note
- LeetCode 383. Ransom Note
- leetcode 383. Ransom Note
- leetcode 383. Ransom Note
- 383.[LeetCode]Ransom Note
- leetcode 383. Ransom Note
- leetcode 383. Ransom Note
- Leetcode 383. Ransom Note
- 【leetcode】383. Ransom Note
- Leetcode 383. Ransom Note
- LeetCode 383. Ransom Note
- [LeetCode]383. Ransom Note
- LeetCode 383. Ransom Note
- [LeetCode]--383. Ransom Note
- LeetCode 383. Ransom Note
- leetcode 383. Ransom Note
- 【LeetCode】 383. Ransom Note
- 已解决:E/WifiManager(4288): WifiServiceMessenger == null....
- Android Studio调试
- #pragma once与#ifndef条件编译区别
- hadoop安装和维护08--部署前调整
- Android 练习错题集
- 【LeetCode】 383. Ransom Note
- HashMap源码学习总结
- 解包、编辑、打包boot.img文件
- Yii i18n国际化,消息翻译
- labwindows例子学习之四波生波器
- 每日一结,HTML
- Android系统字体大小如何影响app的字体大小?
- boot2docker.iso最新版下载
- Android开发——SharedPreferences存储(附:android 的四种枚举Context)