From aec6f6c006298e8c831e3e0f68e64e3cf21b0da1 Mon Sep 17 00:00:00 2001 From: Ali Bektash Date: Mon, 15 Aug 2022 16:33:28 +0900 Subject: [PATCH 1/2] feat: Typescript #1 two sum (#1) --- README.md | 2 +- src/two-sum/res.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/two-sum/res.ts diff --git a/README.md b/README.md index 4d93813..f5edef8 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr | ID | Title | Solution | Difficulty | |-----|-------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|------------| -| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | [JavaScript](./src/two-sum/res.js) | Easy | +| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | [JavaScript](./src/two-sum/res.js)ยท [TypeScript](./src/two-sum/res.ts) | Easy | | 2 | [Add Two Numbers](https://leetcode.com/problems/add-two-numbers/) | [JavaScript](./src/add-two-numbers/res.js) | Medium | | 3 | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | [JavaScript](./src/longest-substring-without-repeating-characters/res.js) | Medium | | 4 | [Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/) | [JavaScript](./src/median-of-two-sorted-arrays/res.js) | Hard | diff --git a/src/two-sum/res.ts b/src/two-sum/res.ts new file mode 100644 index 0000000..10004d6 --- /dev/null +++ b/src/two-sum/res.ts @@ -0,0 +1,28 @@ +/** + * Problem: Given an array of integers, return indices of the two numbers such that they add up to a specific target. + * + * You may assume that each input would have exactly one solution, and you may not use the same element twice. + * + * + * @param {number[]} nums + * @param {number} target + * @return {number[]} + */ + + const twoSum =(nums:Array, target:number): Array => { + + for (let i = nums.length - 1; i >= 0; i--) { + for (let j = 0; j < i; j++) { + if ( addition(nums[i], nums[j]) === target ) { + return [j, i]; + } + } + } + + return []; +}; + +// add a with b and return it +const addition = (a:number, b:number) => { + return a + b; +}; \ No newline at end of file From 4c0b71235068a622a844ee2cdd30f1353dc2aed3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 11 Jan 2024 17:04:28 +0800 Subject: [PATCH 2/2] build(deps-dev): bump word-wrap from 1.2.3 to 1.2.4 (#2) Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4. - [Release notes](https://github.com/jonschlinkert/word-wrap/releases) - [Commits](https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.4) --- updated-dependencies: - dependency-name: word-wrap dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2f2cf84..0ee53a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2478,11 +2478,10 @@ } }, "node_modules/word-wrap": { - "version": "1.2.3", - "resolved": "https://mirrors.tencent.com/npm/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.4.tgz", + "integrity": "sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==", "dev": true, - "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -4137,9 +4136,9 @@ } }, "word-wrap": { - "version": "1.2.3", - "resolved": "https://mirrors.tencent.com/npm/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.4.tgz", + "integrity": "sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==", "dev": true }, "wrappy": {