Skip to content

Commit be08a7f

Browse files
committed
find-all-numbers-disappeared-in-an-array
1 parent bd797af commit be08a7f

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ https://leetcode-cn.com/problems/powx-n/
2828

2929
https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof/
3030

31+
https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array
32+
3133
#### 安装教程
3234

3335
1. 安装`deno`
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default function findDisappearedNumbers(nums: number[]): number[] {
2+
const range: Array<number | undefined> = Array.from({
3+
length: nums.length,
4+
}).map((_v, i) => i + 1);
5+
nums.forEach((v) => {
6+
range[v - 1] = undefined;
7+
});
8+
9+
return range.filter((a) => typeof a !== "undefined") as number[];
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { find_all_numbers_disappeared_in_an_array } from "../mod.ts";
2+
import { assertEquals } from "../deps.ts";
3+
4+
Deno.test("find-all-numbers-disappeared-in-an-array", () => {
5+
const examples: {
6+
input: Parameters<typeof find_all_numbers_disappeared_in_an_array>[0];
7+
output: ReturnType<typeof find_all_numbers_disappeared_in_an_array>;
8+
}[] = [
9+
{ input: [4, 3, 2, 7, 8, 2, 3, 1], output: [5, 6] },
10+
{ input: [1, 1], output: [2] },
11+
{ input: [10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11], output: [] },
12+
];
13+
examples.forEach(({ input, output }) => {
14+
assertEquals(output, find_all_numbers_disappeared_in_an_array(input));
15+
});
16+
});
17+

mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ export {
2424
ListNodeToArray,
2525
} from "./reverse-linked-list/index.ts";
2626
export { default as que_shi_de_shu_zi_lcof } from "./que-shi-de-shu-zi-lcof/index.ts";
27+
export { default as find_all_numbers_disappeared_in_an_array } from "./find-all-numbers-disappeared-in-an-array/index.ts";

0 commit comments

Comments
 (0)