Leetcode771.宝石与石头(python)
2019-03-12 14:34
417 查看
771.宝石与石头
给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头。 S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石。
J 中的字母不重复,J 和 S中的所有字符都是字母。字母区分大小写,因此"a"和"A"是不同类型的石头。
示例 1:
输入: J = “aA”, S = “aAAbbbb”
输出: 3
示例 2:
输入: J = “z”, S = “ZZ”
输出: 0
注意:
S 和 J 最多含有50个字母。
J 中的字符不重复。
class Solution def numJewelsInStones(self, J: str, S: str) -> int: flag=0 for i in J: for j in S: if j==i: flag=flag+1 return flag
执行内存60ms
运行内存13.1MB
相关文章推荐
- LeetCode 刷题(python)之 宝石与石头
- Leetcode 771.宝石与石头
- Leetcode771宝石与石头
- Leetcode刷题1-771.宝石与石头(C++)
- Leetcode:宝石与石头
- 【LeetCode】宝石与石头
- python实现 leetcode 771 jewels and stones
- LeetCode宝石与石头(C语言)
- LeetCode 第771题 宝石与石头/Jawels and Stones
- leetcode刷题思路总结_宝石与石头
- [LeetCode]题解(python):034-Search for a Range
- leetcode练习(204) 多种方法求质数 python实现
- Leetcode 075 颜色分类 Python C++ 史上最详细题解系列(多解法)
- [LeetCode]题解(python):070-Climbing Stairs
- [LeetCode]Multiply Strings@python
- [LeetCode]Permutations II@python
- leetcode_[python/C++]_395_Longest Substring with At Least K Repeating Characters_(递归非递归)
- [leetcode]Max Points on a Line @ Python
- LeetCode 74 Search a 2D Matrix(Python详解及实现)
- 【LeetCode with Python】 Remove Nth Node From End of List