Skip to content

Commit aa0b82f

Browse files
committed
test commit
1 parent b7f8b29 commit aa0b82f

File tree

12 files changed

+121
-1
lines changed

12 files changed

+121
-1
lines changed

.github/workflows/publish.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Publish
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
11+
permissions:
12+
contents: read
13+
id-token: write
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Publish package
19+
run: npx jsr publish

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"deno.enable": true
3+
}

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
# JavaScript
1+
# JavaScript
2+
3+
Implementations of LeetCode problem solutions in JavaScript.

deno.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@leetcode/leetcodejs",
3+
"version": "0.0.1",
4+
"exports": "./src/mod.ts",
5+
"tasks": {
6+
"dev": "deno run --watch main.ts"
7+
},
8+
"imports": {
9+
"@std/assert": "jsr:@std/assert@1"
10+
},
11+
"fmt": {
12+
"include": [ "src/", "tests/" ]
13+
},
14+
"lint": {
15+
"include": [ "src/", "tests/" ]
16+
}
17+
}

deno.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/easy.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
3+
* You may assume that each input would have exactly one solution, and you may not use the same element twice.
4+
*
5+
* You can return the answer in any order.
6+
*
7+
* Example 1:
8+
*
9+
* Input: nums = [2,7,11,15], target = 9
10+
* Output: [0,1]
11+
* Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
12+
*
13+
* Example 2:
14+
*
15+
* Input: nums = [3,2,4], target = 6
16+
* Output: [1,2]
17+
*
18+
* Example 3:
19+
*
20+
* Input: nums = [3,3], target = 6
21+
* Output: [0,1]
22+
*
23+
* Constraints:
24+
* - 2 <= nums.length <= 10^4
25+
* - -10^9 <= nums[i] <= 10^9
26+
* - -10^9 <= target <= 10^9
27+
* - Only one valid answer exists.
28+
29+
* @param nums
30+
* @param target
31+
* @returns
32+
*/
33+
export function twoSum(nums: number[], target: number): number[] {
34+
const map: Map<number, number> = new Map();
35+
for (let i = 0; i < nums.length; i++) {
36+
const complement = target - nums[i];
37+
if (map.has(complement)) {
38+
return [map.get(complement), i];
39+
}
40+
map.set(nums[i], i);
41+
}
42+
return [];
43+
}

src/hard.ts

Whitespace-only changes.

src/medium.ts

Whitespace-only changes.

src/mod.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as easy from "./easy.ts";
2+
import * as medium from "./medium.ts";
3+
import * as hard from "./hard.ts";
4+
5+
export { easy, hard, medium };

tests/test_easy.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { assertArrayIncludes } from "@std/assert";
2+
import * as easy from "../src/easy.ts";
3+
4+
Deno.test(function twoSumTest() {
5+
assertArrayIncludes(easy.twoSum([2, 7, 11, 15], 9), [0, 1]);
6+
assertArrayIncludes(easy.twoSum([3, 2, 4], 6), [1, 2]);
7+
assertArrayIncludes(easy.twoSum([3, 3], 6), [0, 1]);
8+
});

tests/test_hard.ts

Whitespace-only changes.

tests/test_medium.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)