DEV Community

Rohan Ravindra Kadam
Rohan Ravindra Kadam

Posted on

LeetCode : Jewels and Stones With Solutions

Hey🖐 DevCommunity Checkout The blog for solutions above Leetcode problem statement

Problem Statement

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".

Example 1:

Input: jewels = "aA", stones = "aAAbbbb"
Output: 3
Enter fullscreen mode Exit fullscreen mode

Example 2:

Input: jewels = "z", stones = "ZZ"
Output: 0
Enter fullscreen mode Exit fullscreen mode

Constraints:

  • 1 <= jewels.length, stones.length <= 50
  • jewels and stones consist of only English letters.
  • All the characters of jewels are unique.

Solution

class Solution {
    public int numJewelsInStones(String jewels, String stones) {
         int count= 0;
        for (char jewel:jewels.toCharArray()) {
            for (char stone:stones.toCharArray()) {
                if(jewel==stone){
                    count++;
                }
            }

        }
        return count;
    }
}
Enter fullscreen mode Exit fullscreen mode

Conclusion

In this article, we learned way to solve LeetCode Problem Statement Jewels and Stones using java.

Checkout More about Me by visiting on below links

Github:- Rohan2596
Website:- kadamrohan.com
Blogs:- rohankadam965.medium.com
Instagram:- rohankadam_codes

Thank You For Reading.Do like ❤ Share and Follow for more content like this.
Also share feedbacks and Solution in the comment section below

Top comments (0)