https://leetcode-cn.com/problems/jewels-and-stones/
Java
public int numJewelsInStones(String J, String S) { if (null == J || null == S || J.isEmpty() || S.isEmpty()) { return 0; } char[] jChars = J.toCharArray(); // ASCII字母为 65~122 byte[] letterArray = new byte[58]; for (char jChar : jChars) { letterArray[jChar - 65] = 1; } char[] sChars = S.toCharArray(); // 宝石总数 int count = 0; for (char sChar : sChars) { if (letterArray[sChar - 65] == 1) { count++; } } return count; }