Skip to content

Commit 79f146b

Browse files
committed
move-zeroes/
1 parent 17dca70 commit 79f146b

File tree

15 files changed

+93
-37
lines changed

15 files changed

+93
-37
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof/
3030

3131
https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array
3232

33+
https://leetcode-cn.com/problems/move-zeroes/
34+
3335
#### 安装教程
3436

3537
1. 安装`deno`

climbing-stairs/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// My code goes here
22
/** https://leetcode-cn.com/problems/climbing-stairs */
3-
export default function climbStairs(n: number): number | bigint {
3+
export default function climbing_stairs(n: number): number | bigint {
44
const result = getClimbStairs(BigInt(n));
55
if (result < Number.MAX_SAFE_INTEGER) {
66
return Number(result);

climbing-stairs/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { assertStrictEquals } from "../deps.ts";
2-
import { climbStairs } from "../mod.ts";
2+
import { climbing_stairs } from "../mod.ts";
33

44
Deno.test("climbing-stairs", () => {
55
const examples: {
66
input: number;
7-
output: ReturnType<typeof climbStairs>;
7+
output: ReturnType<typeof climbing_stairs>;
88
}[] = [
99
{ input: 10, output: 89 },
1010
{ input: 1, output: 1 },
@@ -16,6 +16,6 @@ Deno.test("climbing-stairs", () => {
1616
{ input: 99, output: 354224848179261915075n },
1717
];
1818
examples.forEach(({ input, output }) => {
19-
assertStrictEquals(climbStairs(input), output);
19+
assertStrictEquals(climbing_stairs(input), output);
2020
});
2121
});

fibonacci-number/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// My code goes here
22
/**https://leetcode-cn.com/problems/fibonacci-number/ */
3-
export default function fibonacciNumber(n: number): number | bigint {
3+
export default function fibonacci_Number(n: number): number | bigint {
44
const result = getfbnq(BigInt(n));
55
if (result < Number.MAX_SAFE_INTEGER) {
66
return Number(result);

fibonacci-number/test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { assertStrictEquals } from "../deps.ts";
2-
import { fibonacciNumber } from "../mod.ts";
2+
import { fibonacci_Number } from "../mod.ts";
33

44
Deno.test("fibonacci-number", () => {
55
const examples: {
66
input: number;
7-
output: ReturnType<typeof fibonacciNumber>;
7+
output: ReturnType<typeof fibonacci_Number>;
88
}[] = [
99
{ input: 2, output: 1 },
1010
{ input: 3, output: 2 },
@@ -14,6 +14,6 @@ Deno.test("fibonacci-number", () => {
1414
{ input: 99, output: 218922995834555169026n },
1515
];
1616
examples.forEach(({ input, output }) => {
17-
assertStrictEquals(fibonacciNumber(input), output);
17+
assertStrictEquals(fibonacci_Number(input), output);
1818
});
1919
});

html-entity-parser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**https://leetcode-cn.com/problems/html-entity-parser/*/
2-
export default function htmlEntityParser(text: string): string {
2+
export default function html_Entity_Parser(text: string): string {
33
return text.replace(entityRegExp, replacer);
44
}
55
const replacer = (a: string) => {

html-entity-parser/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { assert } from "../deps.ts";
2-
import { htmlEntityParser } from "../mod.ts";
2+
import { html_Entity_Parser } from "../mod.ts";
33

44
Deno.test("html-entity-parser", () => {
55
const testData: { input: string; output: string }[] = [
@@ -27,7 +27,7 @@ Deno.test("html-entity-parser", () => {
2727

2828
assert(
2929
testData.every(
30-
({ input, output }) => htmlEntityParser(input) === output,
30+
({ input, output }) => html_Entity_Parser(input) === output,
3131
),
3232
);
3333
});

merge-sorted-array/test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { assertEquals } from "../deps.ts";
2-
import { mergeSortedArray } from "../mod.ts";
2+
import { merge_Sorted_Array } from "../mod.ts";
33
Deno.test("merge-sorted-array", () => {
44
const examples: {
5-
input: Parameters<typeof mergeSortedArray>;
6-
output: Parameters<typeof mergeSortedArray>[0];
5+
input: Parameters<typeof merge_Sorted_Array>;
6+
output: Parameters<typeof merge_Sorted_Array>[0];
77
}[] = [
88
{
99
input: [[1, 2, 3, 0, 0, 0], 3, [2, 5, 6], 3],
@@ -13,7 +13,7 @@ Deno.test("merge-sorted-array", () => {
1313
{ input: [[0], 0, [1], 1], output: [1] },
1414
];
1515
examples.forEach(({ input, output }) => {
16-
mergeSortedArray(...input);
16+
merge_Sorted_Array(...input);
1717
assertEquals(output, input[0]);
1818
});
1919
});

mod.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import mergeSortedArray from "./merge-sorted-array/index.ts";
1+
import merge_Sorted_Array from "./merge-sorted-array/index.ts";
22
import pow_x_n from "./powx-n/index.ts";
33

4-
import htmlEntityParser from "./html-entity-parser/index.ts";
4+
import html_Entity_Parser from "./html-entity-parser/index.ts";
55

6-
import reverseLinkedList from "./reverse-linked-list/index.ts";
6+
import reverse_Linked_List from "./reverse-linked-list/index.ts";
77

8-
import climbStairs from "./climbing-stairs/index.ts";
8+
import climbing_stairs from "./climbing-stairs/index.ts";
99
import fei_bo_na_qi_shu_lie_lcof from "./fei-bo-na-qi-shu-lie-lcof/index.ts";
1010

11-
import fibonacciNumber from "./fibonacci-number/index.ts";
12-
import twoSum from "./two-sum/index.ts";
13-
export { fibonacciNumber };
14-
export { twoSum };
15-
export { mergeSortedArray };
16-
export { htmlEntityParser };
17-
export { reverseLinkedList };
18-
export { climbStairs };
11+
import fibonacci_Number from "./fibonacci-number/index.ts";
12+
import two_Sum from "./two-sum/index.ts";
13+
export { fibonacci_Number };
14+
export { two_Sum };
15+
export { merge_Sorted_Array };
16+
export { html_Entity_Parser };
17+
export { reverse_Linked_List };
18+
export { climbing_stairs };
1919
export { fei_bo_na_qi_shu_lie_lcof };
2020
export { pow_x_n };
2121
export {
@@ -25,3 +25,4 @@ export {
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";
2727
export { default as find_all_numbers_disappeared_in_an_array } from "./find-all-numbers-disappeared-in-an-array/index.ts";
28+
export { default as move_zeros } from "./move-zeroes/index.ts";

move-zeroes/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
Do not return anything, modify nums in-place instead.
3+
*/
4+
export default function moveZeroes(nums: number[]): void {
5+
if (nums.length === 0) {
6+
return;
7+
}
8+
const notzeros = nums.filter((a) => a !== 0);
9+
// const zeros=Array(nums.length-notzeros.length).fill(0)
10+
nums.splice(0, notzeros.length, ...notzeros);
11+
for (let i = notzeros.length; i < nums.length; i++) {
12+
nums[i] = 0;
13+
}
14+
// nums.splice(notzeros.length,zeros.length,...zeros)
15+
// nums.sort((a,b)=>{
16+
// return (a!==0&&b!==0)?0:(-Math.abs(a))||(Math.abs(b))
17+
// })
18+
}

0 commit comments

Comments
 (0)