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
반응형
'코딩 문제' 카테고리의 다른 글
LeetCode 62. Unique Path (0) | 2023.07.27 |
---|---|
LeetCode 1768 Merge String Alternately (0) | 2023.07.17 |
[LeetCode] 1720 Decode XORred Array (0) | 2023.01.29 |
[LeetCode] 728. Self Dividing Numbers, C++ (0) | 2023.01.26 |
[LeetCode] 2032. Two Out of Three, C++ (0) | 2023.01.25 |