DEV Community

Rohan Ravindra Kadam
Rohan Ravindra Kadam

Posted on

4 3

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

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

Great read:

Is it Time to go Back to the Monolith?

History repeats itself. Everything old is new again and I’ve been around long enough to see ideas discarded, rediscovered and return triumphantly to overtake the fad. In recent years SQL has made a tremendous comeback from the dead. We love relational databases all over again. I think the Monolith will have its space odyssey moment again. Microservices and serverless are trends pushed by the cloud vendors, designed to sell us more cloud computing resources.

Microservices make very little sense financially for most use cases. Yes, they can ramp down. But when they scale up, they pay the costs in dividends. The increased observability costs alone line the pockets of the “big cloud” vendors.