Skip to content

Commit bd797af

Browse files
committed
que-shi-de-shu-zi-lcof
1 parent 0f2d335 commit bd797af

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

que-shi-de-shu-zi-lcof/index.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
export default function missingNumber(nums: number[]): number {
2-
const len = nums.length;
3-
for (let i = 0; i < len; i++) {
4-
if (i != nums[i]) {
5-
return i;
6-
}
7-
}
8-
return len;
9-
// const range=(Array.from({length:nums.length+1}).map((_v,i)=>i)
10-
11-
// );
12-
// return sum(range)-sum(nums)
13-
14-
// // for(const v of nums){
15-
// // // range[v-1]=undefined
16-
// // if(range[v-1]){}
17-
// // }
18-
// nums.forEach(v=>{
19-
// range[v]=undefined
20-
// })
21-
22-
// return range.filter(a=>typeof a!=="undefined")[0]
23-
}
24-
// function sum(nums: number[]): number{
25-
// return nums.reduce((p,v)=>p+v,0)
26-
// }
1+
export default function missingNumber(nums: number[]): number {
2+
const len = nums.length;
3+
for (let i = 0; i < len; i++) {
4+
if (i != nums[i]) {
5+
return i;
6+
}
7+
}
8+
return len;
9+
// const range=(Array.from({length:nums.length+1}).map((_v,i)=>i)
10+
11+
// );
12+
// return sum(range)-sum(nums)
13+
14+
// // for(const v of nums){
15+
// // // range[v-1]=undefined
16+
// // if(range[v-1]){}
17+
// // }
18+
// nums.forEach(v=>{
19+
// range[v]=undefined
20+
// })
21+
22+
// return range.filter(a=>typeof a!=="undefined")[0]
23+
}
24+
// function sum(nums: number[]): number{
25+
// return nums.reduce((p,v)=>p+v,0)
26+
// }

que-shi-de-shu-zi-lcof/test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { assertStrictEquals } from "../deps.ts";
2-
import { que_shi_de_shu_zi_lcof } from "../mod.ts";
3-
4-
Deno.test("que-shi-de-shu-zi-lcof", () => {
5-
const examples: {
6-
input: Parameters<typeof que_shi_de_shu_zi_lcof>[0];
7-
output: ReturnType<typeof que_shi_de_shu_zi_lcof>;
8-
}[] = [
9-
{ input: [0, 1, 3], output: 2 },
10-
{ input: [0, 1, 2, 3, 4, 5, 6, 7, 9], output: 8 },
11-
{ input: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11], output: 10 },
12-
];
13-
examples.forEach(({ input, output }) => {
14-
assertStrictEquals(output, que_shi_de_shu_zi_lcof(input));
15-
});
16-
});
1+
import { assertStrictEquals } from "../deps.ts";
2+
import { que_shi_de_shu_zi_lcof } from "../mod.ts";
3+
4+
Deno.test("que-shi-de-shu-zi-lcof", () => {
5+
const examples: {
6+
input: Parameters<typeof que_shi_de_shu_zi_lcof>[0];
7+
output: ReturnType<typeof que_shi_de_shu_zi_lcof>;
8+
}[] = [
9+
{ input: [0, 1, 3], output: 2 },
10+
{ input: [0, 1, 2, 3, 4, 5, 6, 7, 9], output: 8 },
11+
{ input: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11], output: 10 },
12+
];
13+
examples.forEach(({ input, output }) => {
14+
assertStrictEquals(output, que_shi_de_shu_zi_lcof(input));
15+
});
16+
});

0 commit comments

Comments
 (0)