Skip to content

Commit 20cf8c1

Browse files
committed
feat: jewels and stones
1 parent e9cbe6e commit 20cf8c1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

str.jewels-and-stones.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
"""
3+
771. 宝石与石头
4+
https://leetcode-cn.com/problems/jewels-and-stones/
5+
给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头。 S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石。
6+
J 中的字母不重复,J 和 S中的所有字符都是字母。字母区分大小写,因此"a"和"A"是不同类型的石头。
7+
"""
8+
def numJewelsInStones(self, J: str, S: str) -> int:
9+
res = 0
10+
for s in S:
11+
if s in J:
12+
res += 1
13+
return res
14+
15+
16+
so = Solution()
17+
print(so.numJewelsInStones('aA', 'aAAbbbb'))

0 commit comments

Comments
 (0)