File tree 2 files changed +31
-1
lines changed
2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,399 LeetCode solutions in JavaScript
1
+ # 1,400 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
591
591
768|[ Max Chunks To Make Sorted II] ( ./solutions/0768-max-chunks-to-make-sorted-ii.js ) |Hard|
592
592
769|[ Max Chunks To Make Sorted] ( ./solutions/0769-max-chunks-to-make-sorted.js ) |Medium|
593
593
770|[ Basic Calculator IV] ( ./solutions/0770-basic-calculator-iv.js ) |Hard|
594
+ 771|[ Jewels and Stones] ( ./solutions/0771-jewels-and-stones.js ) |Easy|
594
595
773|[ Sliding Puzzle] ( ./solutions/0773-sliding-puzzle.js ) |Hard|
595
596
775|[ Global and Local Inversions] ( ./solutions/0775-global-and-local-inversions.js ) |Medium|
596
597
777|[ Swap Adjacent in LR String] ( ./solutions/0777-swap-adjacent-in-lr-string.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments