Skip to content

Added link of lc problem 771 in problems #2009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dsa-problems/leetcode-problems/0700-0799.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export const problems = [
"problemName": "771. Jewels and Stones",
"difficulty": "Easy",
"leetCodeLink": "https://leetcode.com/problems/jewels-and-stones",
"solutionLink": "#"
"solutionLink": "/dsa-solutions/lc-solutions/0700-0799/jewels-and-stones"
},
{
"problemName": "772. Basic Calculator III",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
---
id: jewels-and-stones
title: Jewels and Stones
title: Jewels and Stones
sidebar_label: 771 Jewels and Stones

tags:
- HashTable
- String

description: "This is a solution to the Jewels and Stones on leetcode"
---

## Problem Description

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

Expand Down Expand Up @@ -43,18 +42,17 @@ Output: 0
The problem requires us to determine how many characters from the jewels string are present in the stones string. Each character in jewels represents a type of jewel, and each character in stones represents a stone that may contain one of these jewels. The goal is to count how many stones are jewels.

### Approach
We use a hash-based data structure (an unordered_set in C++ or a HashSet in Java) to store characters from the jewels string. This allows for average O(1) time complexity for membership checks.and we iterate to each character in stones string if that character is present in jewel we increment the count and we return count.
We use a hash-based data structure (an unordered_set in C++ or a HashSet in Java) to store characters from the jewels string. This allows for average $O(1)$ time complexity for membership checks.and we iterate to each character in stones string if that character is present in jewel we increment the count and we return count.


#### Complexity Analysis

- Time Complexity: $O(J+S)$, where J is the length of jewels and S is the length of stones.
- Space Complexity: $O(J)$ , where J is no of distinct characters in jewels.

## Code in Different Languages

<Tabs>
## Code in Different Languages

<Tabs>
<TabItem value="Java" label="Java">
<SolutionAuthor name="@ImmidiSivani" />

Expand All @@ -74,13 +72,11 @@ We use a hash-based data structure (an unordered_set in C++ or a HashSet in Java
}
}
return count;
}}

}}

```

</TabItem>

<TabItem value="Python" label="Python">
<SolutionAuthor name="@ImmidiSivani" />

Expand All @@ -96,13 +92,11 @@ We use a hash-based data structure (an unordered_set in C++ or a HashSet in Java
return c

```

</TabItem>

<TabItem value="c++" label="c++">
<TabItem value="cpp" label="c++">
<SolutionAuthor name="@ImmidiSivani" />

```c++
```cpp
#include <iostream>
#include <unordered_set>

Expand All @@ -121,12 +115,10 @@ We use a hash-based data structure (an unordered_set in C++ or a HashSet in Java
};

```

</TabItem>

</Tabs>
</Tabs>

## References

- **LeetCode Problem**: [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones/solutions/)
- **Solution Link**: [LeetCode Solution](https://leetcode.com/problems/jewels-and-stones/post-solution/?submissionId=1279731526)
- **Solution Link**: [LeetCode Solution](https://leetcode.com/problems/jewels-and-stones/post-solution/?submissionId=1279731526)
Loading