We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b5a1430 commit 2f26845Copy full SHA for 2f26845
src/two-sum.js
@@ -0,0 +1,25 @@
1
+/**
2
+ * Problem: Given an array of integers, return indices of the two numbers such that they add up to a specific target.
3
+ *
4
+ * You may assume that each input would have exactly one solution, and you may not use the same element twice.
5
6
+ * two0sum.js
7
8
+ * @param {number[]} nums
9
+ * @param {number} target
10
+ * @return {number[]}
11
+ */
12
+let twoSum = function(nums, target) {
13
+ for (let i = nums.length - 1; i >= 0; i--) {
14
+ for (let j = 0; j < i; j++) {
15
+ if ( addition(nums[i], nums[j]) === target ) {
16
+ return [j, i];
17
+ }
18
19
20
+};
21
+
22
+// add a with b and return it
23
+let addition = function(a, b) {
24
+ return a + b;
25
0 commit comments