Jewels and Stones
就是字符找匹配
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
class Solution { public int numJewelsInStones(String J, String S) { int res = 0; int[] count = new int[255]; for(int i = 0 ; i < S.length(); i++) { count[S.charAt(i)]++; } for(int i = 0 ; i < J.length(); i++) { res += count[J.charAt(i)]; } return res; } } |