Skip to content

Commit 8474c30

Browse files
authored
Update 0771-jewels-and-stones.md
1 parent f42a29b commit 8474c30

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

dsa-solutions/lc-solutions/0700-0799/0771-jewels-and-stones.md

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
---
22
id: jewels-and-stones
3-
title: Jewels and Stones
3+
title: Jewels and Stones
44
sidebar_label: 771 Jewels and Stones
5-
65
tags:
76
- HashTable
87
- String
9-
108
description: "This is a solution to the Jewels and Stones on leetcode"
119
---
1210

1311
## Problem Description
12+
1413
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.
1514
Letters are case sensitive, so "a" is considered a different type of stone from "A".
1615

@@ -43,18 +42,17 @@ Output: 0
4342
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.
4443

4544
### Approach
46-
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.
45+
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.
4746

4847

4948
#### Complexity Analysis
5049

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

54-
## Code in Different Languages
55-
56-
<Tabs>
53+
## Code in Different Languages
5754

55+
<Tabs>
5856
<TabItem value="Java" label="Java">
5957
<SolutionAuthor name="@ImmidiSivani" />
6058

@@ -74,13 +72,11 @@ We use a hash-based data structure (an unordered_set in C++ or a HashSet in Java
7472
}
7573
}
7674
return count;
77-
}}
78-
75+
}}
7976

8077
```
8178

8279
</TabItem>
83-
8480
<TabItem value="Python" label="Python">
8581
<SolutionAuthor name="@ImmidiSivani" />
8682

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

9894
```
99-
10095
</TabItem>
101-
102-
<TabItem value="c++" label="c++">
96+
<TabItem value="cpp" label="c++">
10397
<SolutionAuthor name="@ImmidiSivani" />
10498

105-
```c++
99+
```cpp
106100
#include <iostream>
107101
#include <unordered_set>
108102

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

123117
```
124-
125118
</TabItem>
126-
127-
</Tabs>
119+
</Tabs>
128120

129121
## References
130122

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

0 commit comments

Comments
 (0)