题目链接:https://leetcode.com/problems/jewels-and-stones/description/
题目解析:利用字符的ACSII离散化一下,确定有没有出现即可。
代码如下:0ms Accepted
class Solution {
public:
int numJewelsInStones(string J, string S) {
int mp[200]={0};
for (auto c : J)
mp[c] = 1;
int cnt = 0;
for (auto c : S)
if (mp[c])
cnt++;
return cnt;
}
};
static const auto ____ = [] () {
ios::sync_with_stdio(false);
cin.tie(nullptr);
return nullptr;
}();
本文解析了LeetCode上的一道题目“珠宝与石头”,并提供了一个0ms的高效解决方案。通过ASCII离散化的方法,判断每个字符是否为珠宝,从而计算出石头中包含的珠宝数量。
426

被折叠的 条评论
为什么被折叠?



