Skip to content

Commit 0f2d335

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

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ https://leetcode-cn.com/problems/merge-sorted-array/
2626

2727
https://leetcode-cn.com/problems/powx-n/
2828

29+
https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof/
30+
2931
#### 安装教程
3032

3133
1. 安装`deno`

mod.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@ import pow_x_n from "./powx-n/index.ts";
33

44
import htmlEntityParser from "./html-entity-parser/index.ts";
55

6-
export {
7-
ArrayToListNode,
8-
ListNode,
9-
ListNodeToArray,
10-
} from "./reverse-linked-list/index.ts";
116
import reverseLinkedList from "./reverse-linked-list/index.ts";
12-
export { pow_x_n };
7+
138
import climbStairs from "./climbing-stairs/index.ts";
149
import fei_bo_na_qi_shu_lie_lcof from "./fei-bo-na-qi-shu-lie-lcof/index.ts";
1510

@@ -22,3 +17,10 @@ export { htmlEntityParser };
2217
export { reverseLinkedList };
2318
export { climbStairs };
2419
export { fei_bo_na_qi_shu_lie_lcof };
20+
export { pow_x_n };
21+
export {
22+
ArrayToListNode,
23+
ListNode,
24+
ListNodeToArray,
25+
} from "./reverse-linked-list/index.ts";
26+
export { default as que_shi_de_shu_zi_lcof } from "./que-shi-de-shu-zi-lcof/index.ts";

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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+
// }

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +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+
});

0 commit comments

Comments
 (0)