leetcode771.宝石与石头
2019-05-06 01:03
302 查看
leetcode771.宝石与石头
代码
//C++ class Solution { public: int numJewelsInStones(string J, string S) { int ans = 0; for (int i=0; i<J.length(); i++){ for (int j=0; j<S.length(); j++){ if (J[i]==S[j]) ans ++; } } return ans; } };
# python2.7 class Solution(object): def numJewelsInStones(self, J, S): """ :type J: str :type S: str :rtype: int """ return sum(S.count(i) for i in J)
总结
- python中a.count(x),计算x出现次数
相关文章推荐
- LeetCode编程771:宝石与石头
- LeetCode每日刷题Day1--- 771 宝石与石头
- Leetcode771宝石与石头
- Leetcode 771.宝石与石头
- Leetcode771.宝石与石头(python)
- (Python)LeetCode刷题笔记——771、宝石与石头
- Leetcode刷题1-771.宝石与石头(C++)
- Leetcode 771. 宝石与石头
- LeetCode宝石与石头(C语言)
- leetcode刷题思路总结_宝石与石头
- 【LeetCode】宝石与石头
- Leetcode:宝石与石头
- 771.宝石与石头
- leetcode题解——771. 宝石与石头
- LeetCode 刷题(python)之 宝石与石头
- LeetCode 第771题 宝石与石头/Jawels and Stones
- LeetCode 开坑纪念-水题771-Jewels and Stones
- leetcode 771 Jewels and Stones
- leetcode771——Jewels and Stones
- 771.Jewels and Stones (leetcode)