[코테 풀이] Jewels and Stones

시내·2024년 6월 10일
0

Q_771) Jewels and Stones

출처 : https://leetcode.com/problems/jewels-and-stones/

You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels.

Letters are case sensitive, so "a" is considered a different type of stone from "A".

class Solution {
    public int numJewelsInStones(String jewels, String stones) {
       int count = 0;
        String[] j = jewels.split("");
        String[] s = stones.split("");
        for (int a = 0; a < s.length; a++) {
            for (int b = 0; b < j.length; b++) {
                if (s[a].equals(j[b])) count++;
            }
        }
        return count;  
    }
}
profile
contact 📨 ksw08215@gmail.com

0개의 댓글