Skip to content

Commit a97f133

Browse files
author
Kohei Asai
authored
1217. Play with Chips (axross#120)
1 parent 3988d38 commit a97f133

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Diff for: solutions/play_with_chips.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// 1217. Play with Chips
2+
// https://leetcode.com/problems/play-with-chips/
3+
export default function minCostToMoveChips(chips: number[]): number {
4+
return Math.min(
5+
...chips.reduce(
6+
([odd, even], chip) =>
7+
chip % 2 === 1 ? [odd + 1, even] : [odd, even + 1],
8+
[0, 0]
9+
)
10+
);
11+
}

Diff for: solutions/play_with_chips_test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { test } from "https://deno.land/std/testing/mod.ts";
2+
import { assertStrictEq } from "https://deno.land/std/testing/asserts.ts";
3+
import minCostToMoveChips from "./play_with_chips.ts";
4+
5+
test("1217. Play with Chips", () => {
6+
assertStrictEq(minCostToMoveChips([1, 2, 3]), 1);
7+
assertStrictEq(minCostToMoveChips([2, 2, 2, 3, 3]), 2);
8+
assertStrictEq(minCostToMoveChips([1, 2, 3, 4, 5, 6, 7, 8, 9]), 4);
9+
});

0 commit comments

Comments
 (0)