본문 바로가기
Problem Solving/LeetCode

[LeetCode] 771. Jewels and Stones - Java

by graycode 2026. 10. 13.

• 문제 링크

 

Jewels and Stones - LeetCode

Can you solve this real interview question? 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 kno

leetcode.com

 

• 풀이 코드

public class Solution {

    public int numJewelsInStones(String jewels, String stones) {
        boolean[] arr = new boolean[128];
        for (char c : jewels.toCharArray()) arr[c] = true;

        int cnt = 0;
        for (char c : stones.toCharArray()) if (arr[c]) cnt++;

        return cnt;
    }

}

댓글