题解 | 宝石计数

宝石计数

https://www.nowcoder.com/practice/d7c20bd9aa094e35b465b566eec86cf2

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param jewels string字符串 
# @param stones string字符串 
# @return int整型
#
import bisect
class Solution:
    def numJewelsInStones(self , jewels: str, stones: str) -> int:
        # write code here
        S =set()#存储j中所有不同的字符
        result = 0 
        for char in jewels:
            S.add(char)        
        for char in stones:
            if char in S:#若set中有s的字符 结果+1
                result+=1
        return result  


全部评论

相关推荐

牛客52811839...:实习要写出来业务和产出,你这写的像流水账没人看。项目经历也没有,换个极简简历试试
点赞 评论 收藏
分享
03-20 17:35
武汉大学 Java
幻想成为offer高...:项目基本都是vibe coding上去的,能跑就行,具体细节还真不知道。。。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务