Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9c954d6

Browse filesBrowse files
author
Kohei Asai
authored
771. Jewels and Stones (#129)
1 parent ccb2234 commit 9c954d6
Copy full SHA for 9c954d6

File tree

2 files changed

+25
-0
lines changed
Filter options

2 files changed

+25
-0
lines changed

‎solutions/jewels_and_stones.ts

Copy file name to clipboard
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// 771. Jewels and Stones
2+
// https://leetcode.com/problems/jewels-and-stones/
3+
export default function numJewelsInStones(
4+
jewelChars: string,
5+
stoneChars: string
6+
) {
7+
const jewels = new Set([...jewelChars]);
8+
let jewelCount = 0;
9+
10+
for (const s of stoneChars) {
11+
if (jewels.has(s)) {
12+
jewelCount += 1;
13+
}
14+
}
15+
16+
return jewelCount;
17+
}

‎solutions/jewels_and_stones_test.ts

Copy file name to clipboard
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test } from "https://deno.land/std/testing/mod.ts";
2+
import { assertStrictEq } from "https://deno.land/std/testing/asserts.ts";
3+
import numJewelsInStones from "./jewels_and_stones.ts";
4+
5+
test("771. Jewels and Stones", () => {
6+
assertStrictEq(numJewelsInStones("aA", "aAAbbbb"), 3);
7+
assertStrictEq(numJewelsInStones("z", "ZZ"), 0);
8+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.