leetCode题解之Jewels and Stones
Posted 山里的小勇子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetCode题解之Jewels and Stones相关的知识,希望对你有一定的参考价值。
1、题目描述
2、分析
使用HashTable 是解决这种的好方法。
3、代码
1 int numJewelsInStones(string J, string S) { 2 map<char,int> m; 3 for(char c : S) 4 m[c]++; 5 6 int ans = 0; 7 for( char c: J) 8 ans += m[c]; 9 return ans; 10 11 }
以上是关于leetCode题解之Jewels and Stones的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode 771. Jewels and Stones
LeetCode 771. Jewels and Stones
[leetcode-771-Jewels and Stones]
Leetcode #771. Jewels and Stones