leetcode刷题(二)
题目地址:https://leetcode.com/problems/jewels-and-stones/description/
问题描述:有两堆东西,一堆J是已知的宝石,另一堆S不确定是否是宝石,要求返回S中宝石的个数
我的代码:
class Solution {
public:
int numJewelsInStones(string J, string S) {
int k=0;
int CountJ=J.size();
int CountS=S.size();
for(int i=0;i<CountJ;i++)
{
for(int j=0;j<CountS;j++)
{
if(J[i]==S[j])
k++;
}
}
return k;
}
};
性能尚且中等,参考大佬的代码的过程中发现大家的性能差不多,可能暂时没有什么更好的解决方案吧,之后找到了再更