Skip to content

Commit 64a4a4f

Browse files
authoredMay 6, 2020
chore(lab): add new exercises
* chore(lab): critial routers exercise * solve the problem but with repetitions * 🔧 chore (lab): solve the problem * --wip-- [skip ci] * --wip-- [skip ci] * feat(lab): integer to words * feat(lab): improve algo to cover corner cases * chore(lab): alien dictionary exercise * chore(lab): sum exercises added * new exercise * using dijkstra algorithm * new exercises * update exercises * new exercise * solution * 🔧 chore eslint
1 parent bcc81b4 commit 64a4a4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+11752
-5974
lines changed
 

‎.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ module.exports = {
1515

1616
// https://eslint.org/docs/rules/no-plusplus
1717
// allows unary operators ++ and -- in the afterthought (final expression) of a for loop.
18-
'no-plusplus': [2, { 'allowForLoopAfterthoughts': true }],
18+
'no-plusplus': [0, { 'allowForLoopAfterthoughts': true }],
19+
'no-continue': [0],
1920

2021
// Allow for..of
2122
'no-restricted-syntax': [0, 'ForOfStatement'],

‎lab/exercises/10-mixed/2sum-1.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
/**
3+
* Given a SORTED array and a target, return the indices of the 2 number that sum up target
4+
*
5+
* @param {number[]} nums
6+
* @param {numer} target
7+
* @returns
8+
*
9+
* @runtime O(n)
10+
*/
11+
function twoSum(nums, target) {
12+
const len = nums.length - 1;
13+
let lo = 0;
14+
let hi = len;
15+
16+
while (lo < hi && hi > 0 && lo < len) {
17+
const sum = nums[lo] + nums[hi];
18+
if (sum === target) {
19+
return [lo, hi];
20+
}
21+
if (sum > target) {
22+
hi--;
23+
} else {
24+
lo++;
25+
}
26+
}
27+
28+
return [];
29+
}
30+
31+
module.exports = twoSum;

0 commit comments

Comments
 (0)
Please sign in to comment.