Saturday, January 27, 2018

LeetCode 771. Jewels and Stones - Weekly Contest 69

https://leetcode.com/contest/weekly-contest-69/problems/jewels-and-stones/


class Solution {
public int numJewelsInStones(String J, String S) {
if (S == null || S.length() < 1 || J == null || J.length() < 1) {
return 0;
}
int[] L = new int[500];
for(int i = 0; i < J.length(); i++) {
L[J.charAt(i)] = 1;
}
int count = 0;
for(int i = 0; i < S.length(); i++) {
if(L[S.charAt(i)] == 1) {
count++;
}
}
return count;
}
}

No comments:

Post a Comment