[LeetCode&Python] Problem 383. Ransom Note
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
from collections import Counter
class Solution(object):
def canConstruct(self, ransomNote, magazine):
"""
:type ransomNote: str
:type magazine: str
:rtype: bool
"""
c=Counter(magazine)
for i in ransomNote:
if c[i]==0 or i not in c:
return False
else:
c[i]-=1
return True
[LeetCode&Python] Problem 383. Ransom Note的更多相关文章
- 383. Ransom Note【easy】
383. Ransom Note[easy] Given an arbitrary ransom note string and another string containing letters f ...
- 【LeetCode】383. Ransom Note 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 [LeetCo ...
- leetcode 383. Ransom Note
Given an arbitrary ransom note string and another string containing letters from all th ...
- leetcode修炼之路——383. Ransom Note
题目是这样的 Given an arbitrary ransom note string and another string containing letters from a ...
- 14. leetcode 383. Ransom Note
Given an arbitrary ransom note string and another string containing letters from all the magazines, ...
- Java [Leetcode 383]Ransom Note
题目描述: Given an arbitrary ransom note string and another string containing letters from al ...
- LeetCode: 383 Ransom Note(easy)
题目: Given an arbitrary ransom note string and another string containing letters from all the magazin ...
- 383. Ransom Note
Given an arbitrary ransom note string and another string containing letters from all th ...
- 383. Ransom Note 在字典数组中查找笔记数组
[抄题]: Given an arbitrary ransom note string and another string containing letters from all the magaz ...
随机推荐
- Qt一步一步实现插件通信(附源码)
前一章已经实现了主程序调用加载插件功能,这一章描述主程序和插件间通信功能 说道Qt的通信必须要了解信号和槽的机制原理,这里不做论述,不清楚的同学去看看信号和槽机制 不废话直接上步骤,在上一章的基础 ...
- was重要文件位置备忘
软件版本信息--/was/profiles/lsDmgr/properties/version/profile.version(/was/bin/versionInfo.sh) profile模版位置 ...
- VSS迁移详细教程
本文默认迁移机和目标机已是安装好VSS服务,如果没装好参见VSS+SourceAnywhere for VSS搭建版本控制系统教程 如果你只想以最快的速度迁移库而并不关心VSS的一些操作使用,那么可直 ...
- python 自然语言处理(五)____WordNet
WordNet是面向语义的英语词典,与传统辞典类似,但结构更丰富.nltk中包括英语WordNet,共有155287个单词和117659个同义词. 1.寻找同义词 这里以motorcar为例,寻找它的 ...
- linux nginx 安装防火墙ngx_lua_waf
ngx_lua_waf是一款开源的 基于 ngx_lua的 web应用防火墙 github地址是 https://github.com/loveshell/ngx_lua_waf 安装流程如下 1 ...
- vs2017 Mariadb/mysql之旅
记录vs2017使用 ef6+mysql的开发 填坑之旅.我的环境 vm+centos7+ docker-ce+mariadb+vs2017 总的原则是MySql.Data.Entity 要和 mys ...
- sys 模块
import sys #环境变量 print(sys.path) #查看已经加载的模块 print(sys.modules) #获取终端调用时的参数 print(sys.argv) #获取解释器的版本 ...
- Module loader:模块加载器
<p data-height="265" data-theme-id="0" data-slug-hash="XpqRmq" data ...
- Unity中Button按钮的触发监听事件
第一种方式:需要把自己添加的Button按钮属性(Inspector)中的(Button)onclick添加方法. public void BtnCreteClick() { Debug.Log(&q ...
- [Codeforces708E]Student's Camp
Problem 一个n*m块砖的建筑,一共k天,每天风从两边吹,吹掉砖的概率为p,反之为1-p,求最终建筑没有倒塌的可能性(上层与下层有交集且每一层都有砖) Solution 首先,我们可以预处理出p ...