Leetcode #383 Ransom Note
来源:互联网 发布:小学教师网络研修日志 编辑:程序博客网 时间:2024/06/07 19:20
Description
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”) -> false
canConstruct(“aa”, “ab”) -> false
canConstruct(“aa”, “aab”) -> true
Explain
统计一个字符串各字母出现的次数,然后在另一个字符串里减即可,刚好python里有个计数的Counter
Code
class Solution(object): def canConstruct(self, ransomNote, magazine): """ :type ransomNote: str :type magazine: str :rtype: bool """ import collections return not collections.Counter(ransomNote) - collections.Counter(magazine)
0 0
- 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--No.383--Ransom Note
- leetcode 383 Ransom Note C++
- LeetCode(383)Ransom Note
- 【LeetCode-383】Ransom Note(C++)
- [LeetCode-383]Ransom Note(java)
- 【LeetCode】383 Ransom Note(java)
- LeetCode 383:Ransom Note (c++)
- C++实验6
- POJ 2777(线段树 位运算)
- Hibernate 映射关系 一对多 单向映射文件配置
- 20170309技术积累2
- JSTL及其POM配置
- Leetcode #383 Ransom Note
- VPS搭建Web服务器(JDK,Tomcat,Nginx,MySQL,SSL)
- C#笔记整理(四)
- MariaDB及HeidiSQL Windows安装
- js 程序执行与顺序实现详解
- ionic2的返回按钮修改和tab上下显示的翻译
- 从 JDBC 类型映射到 Java 类型
- HTML/CSS知识点
- 51nod1255【贪心-栈的应用】