Skip to content

Commit e17b663

Browse files
committed
https://leetcode.cn/problems/find-first-and-last-position-of-element-in-sorted-array/
1 parent 0dddae0 commit e17b663

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ leetcode 测试
1010

1111
##### 包含的内容如下
1212

13+
https://leetcode.cn/problems/find-first-and-last-position-of-element-in-sorted-array/
14+
1315
https://leetcode.cn/problems/rearrange-spaces-between-words/
1416

1517
https://leetcode.cn/problems/count-complete-tree-nodes/

deps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ export { default as sum } from "https://cdn.skypack.dev/[email protected]/sum?dts";
2727
export {
2828
runScript,
2929
TreeNode,
30-
} from "https://cdn.skypack.dev/[email protected].4?dts";
30+
} from "https://esm.sh/@masx200/[email protected].5";
3131
export { default as group } from "https://esm.sh/[email protected]";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default function searchRange(nums: number[], target: number): number[] {
2+
const right = le(nums, target);
3+
const left = ge(nums, target);
4+
if (nums[left] === target && nums[right] === target) {
5+
return [left, right];
6+
}
7+
return [-1, -1];
8+
}
9+
import { ge, le } from "https://esm.sh/@masx200/[email protected]";
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
2+
import searchRange from "./index.ts";
3+
Deno.test("find-first-and-last-position-of-element-in-sorted-array", () => {
4+
const inputs: [nums: number[], target: number][] = [
5+
[[5, 7, 7, 8, 8, 10], 8],
6+
[[5, 7, 7, 8, 8, 10], 6],
7+
[[], 0],
8+
];
9+
assertEquals(
10+
inputs.map(([a, b]) => searchRange(a, b)),
11+
[
12+
[3, 4],
13+
[-1, -1],
14+
[-1, -1],
15+
]
16+
);
17+
});

import_map.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"imports": {
3-
"leetcode-class": "https://cdn.skypack.dev/[email protected].4?dts",
3+
"leetcode-class": "https://esm.sh/@masx200/[email protected].5",
44
"asserts": "https://deno.land/[email protected]/testing/asserts.ts"
55
}
66
}

0 commit comments

Comments
 (0)