Skip to content

Commit 538a568

Browse files
committed
Add solution #771
1 parent 8016e6c commit 538a568

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,399 LeetCode solutions in JavaScript
1+
# 1,400 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -591,6 +591,7 @@
591591
768|[Max Chunks To Make Sorted II](./solutions/0768-max-chunks-to-make-sorted-ii.js)|Hard|
592592
769|[Max Chunks To Make Sorted](./solutions/0769-max-chunks-to-make-sorted.js)|Medium|
593593
770|[Basic Calculator IV](./solutions/0770-basic-calculator-iv.js)|Hard|
594+
771|[Jewels and Stones](./solutions/0771-jewels-and-stones.js)|Easy|
594595
773|[Sliding Puzzle](./solutions/0773-sliding-puzzle.js)|Hard|
595596
775|[Global and Local Inversions](./solutions/0775-global-and-local-inversions.js)|Medium|
596597
777|[Swap Adjacent in LR String](./solutions/0777-swap-adjacent-in-lr-string.js)|Medium|

solutions/0771-jewels-and-stones.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* 771. Jewels and Stones
3+
* https://leetcode.com/problems/jewels-and-stones/
4+
* Difficulty: Easy
5+
*
6+
* You're given strings jewels representing the types of stones that are jewels, and stones
7+
* representing the stones you have. Each character in stones is a type of stone you have.
8+
* You want to know how many of the stones you have are also jewels.
9+
*
10+
* Letters are case sensitive, so "a" is considered a different type of stone from "A".
11+
*/
12+
13+
/**
14+
* @param {string} jewels
15+
* @param {string} stones
16+
* @return {number}
17+
*/
18+
var numJewelsInStones = function(jewels, stones) {
19+
const set = new Set(jewels);
20+
let result = 0;
21+
22+
for (const stone of stones) {
23+
if (set.has(stone)) {
24+
result++;
25+
}
26+
}
27+
28+
return result;
29+
};

0 commit comments

Comments
 (0)