(LeetCode)Ransom Note --- 勒索信(字符串问题)
来源:互联网 发布:win7虚拟机mac os x 编辑:程序博客网 时间:2024/05/17 20:29
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
解题分析:
字符串匹配问题,注意几点,首先
只要统计两个字符串中对应字符的个数,以及存在的字符就OK了。
# -*- coding:utf-8 -*-__author__ = 'jiuzhang'from collections import Counterclass Solution(object): def canConstruct(self, ransomNote, magazine): if ransomNote == '': return True if magazine == '': return False note = Counter(ransomNote) mag = Counter(magazine) for i in note.keys(): print i if None == mag.get(i) or not[i] > mag.get(i): return False else: return True
0 0
- (LeetCode)Ransom Note --- 勒索信(字符串问题)
- leetcode 383. Ransom Note 勒索信
- 383. Ransom Note(勒索信)
- LeetCode Ransom Note(字符串)
- LeetCode(383)Ransom Note
- Leetcode - String - 383. Ransom Note(水题)
- 【LeetCode】383 Ransom Note(java)
- LeetCode 383. Ransom Note 题解(C++)
- LeetCode oj 383. Ransom Note(哈希)
- LeetCode 383:Ransom Note (c++)
- Leetcode- 383. Ransom Note(string)
- leetcode-383. Ransom Note
- [leetcode] 383. Ransom Note
- LeetCode:383 Ransom Note
- 【Leetcode】Ransom Note
- LeetCode 383. Ransom Note
- Leetcode Ransom Note
- LeetCode#383 Ransom Note
- error while loading shared libraries: xxx.so.x" 错误的原因和解决办法
- linux下的gedit命令使用方法与技巧
- 移动端适配方案(上)
- Spring中的ContextLoaderListener使用
- 字字珠玑
- (LeetCode)Ransom Note --- 勒索信(字符串问题)
- 详细解读Jquery各Ajax函数:
- android fragment
- C语言经典算法11
- HTTPS和HTTP的区别
- CSS的相关新属性
- codeforces 725B Food on the Plane
- [搜索+剪枝/]poj1054 The Troublesome Frog
- CodeForces 725A Jumping Ball