코딩 문제
[LeetCode] 771, Jewels and Stones
Zach Choi
2023. 2. 14. 07:25
728x90
반응형
Skill
- Use hash table to decrease time complexity to under log(n^2)
Others
- Use string struct member
- Use ASCII Number of english letter
int gstHashTable[60] = { 0 };
class Solution {
public:
int numJewelsInStones(string jewels, string stones) {
memset(&gstHashTable, 0, sizeof(int) * 60);
int RetVal = 0;
for (int i = 0; i != stones.size(); ++i)
{
gstHashTable[stones[i] - 65]++;
}
for (int i = 0; i != jewels.size(); ++i)
{
RetVal += gstHashTable[jewels[i] - 65];
}
return RetVal;
}
};
728x90
반응형