LeetCode : Jewels and Stones With Solutions
Rohan Ravindra Kadam
Posted on June 6, 2022
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
Example 2:
Input: jewels = "z", stones = "ZZ"
Output: 0
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;
}
}
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
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
November 8, 2024