LeetCode : Jewels and Stones With Solutions

rohan2596

Rohan Ravindra Kadam

Posted on June 6, 2022

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

๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
rohan2596
Rohan Ravindra Kadam

Posted on June 6, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Happy programming day
javascript Happy programming day

September 12, 2024

Proxy Puzzle
javascript Proxy Puzzle

October 9, 2023

JavaScript vs. Python
javascript JavaScript vs. Python

September 3, 2023

ยฉ TheLazy.dev

About