題目: LeetCode - 771. Jewels and Stones

題目說明

給兩個字串 JS,求 S 裡面有多少個字元與 J 裡面的字元相同。

解題思路

使用 String 裡面的 find() 即可。

參考解法

1
2
3
4
5
6
7
8
9
10
class Solution {
public:
int numJewelsInStones(string J, string S) {
int count = 0;
for(auto i : S)
if(J.find(i) != -1)
++count;
return count;
}
};