Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 04a3e81

Browse files
hot9cupsignacio-chiazzo
authored andcommitted
EsLint and Tests fix
- A lot of files had Linting issues. Used EsLint to fix all the troublesome files. - Fixed the tests that were failing. Node Tests.js should run just fine now!
1 parent c02cf2c commit 04a3e81

File tree

91 files changed

+449
-446
lines changed

Some content is hidden

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

91 files changed

+449
-446
lines changed

‎LeetcodeProblems/Algorithms/2Sum.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var twoSum = function (nums, target) {
3232
let map = {};
3333
for (let i = 0; i < nums.length; i++) {
3434
const sum = target - nums[i];
35-
if (map[parseInt(sum)]!=0) {
35+
if (suminmap) {
3636
return [map[sum], i];
3737
} else {
3838
map[nums[i]] = i;
@@ -43,8 +43,8 @@ var twoSum = function (nums, target) {
4343
//Another method
4444
var twoSum2 = function (nums, target) {
4545
for (let i = 0; i < nums.length; i++) {
46-
for (let j = i + 1; j < nums.length; i++) {
47-
if (nums[1] + nums[j] === target) {
46+
for (let j = i + 1; j < nums.length; j++) {
47+
if (nums[i] + nums[j] === target) {
4848
return [i, j];
4949
}
5050
}

‎LeetcodeProblems/Algorithms/3SumClosest.js‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,31 @@ Constraints:
3030
* @param {number} target
3131
* @return {number}
3232
*/
33-
var threeSumClosest = function(nums, target) {
33+
var threeSumClosest = function(nums, target) {
3434
let mid = 1;
3535
let right = nums.length - 1;
3636
let currentSum = nums[0] + nums[mid] + nums[right];
3737
let closest = currentSum;
3838

39-
nums.sort(function(a,b) {return a - b})
39+
nums.sort(function(a,b) {return a - b;});
4040

4141
for(var left = 0 ; left < nums.length - 1; left++) {
42-
mid = left + 1;
43-
right = nums.length - 1;
42+
mid = left + 1;
43+
right = nums.length - 1;
4444

45-
while(mid < right) {
46-
currentSum = nums[left] + nums[mid] + nums[right];
45+
while(mid < right) {
46+
currentSum = nums[left] + nums[mid] + nums[right];
4747

48-
if(Math.abs(target - currentSum) < Math.abs(target - closest)) {
49-
closest = currentSum;
50-
}
48+
if(Math.abs(target - currentSum) < Math.abs(target - closest)) {
49+
closest = currentSum;
50+
}
5151

52-
if(currentSum > target) {
53-
right--;
54-
} else {
55-
mid++;
56-
}
52+
if(currentSum > target) {
53+
right--;
54+
} else {
55+
mid++;
5756
}
57+
}
5858
}
5959

6060
return closest;

‎LeetcodeProblems/Algorithms/Container_With_Most_Water.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ Output: 1
2424
* @param {number[]} height
2525
* @return {number}
2626
*/
27-
var maxArea = function(height) {
27+
var maxArea = function(height) {
2828
let left = 0;
2929
let right = height.length - 1;
3030
let maxArea = calculateArea(left, right, height);
3131

3232
while(left < right) {
33-
if(height[left] < height[right]) {
34-
left++
35-
} else {
36-
right--;
37-
}
38-
maxArea = Math.max(maxArea, calculateArea(left, right, height))
33+
if(height[left] < height[right]) {
34+
left++;
35+
} else {
36+
right--;
37+
}
38+
maxArea = Math.max(maxArea, calculateArea(left, right, height));
3939
}
4040
return maxArea;
4141
};
@@ -44,6 +44,6 @@ var calculateArea = function(x, y, height) {
4444
let minHeight = height[x] > height[y] ? height[y] : height[x];
4545
let width = y -x;
4646
return (width * minHeight);
47-
}
47+
};
4848

4949
module.exports.maxArea = maxArea;

‎LeetcodeProblems/Algorithms/Find_Anagrams.js‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,51 +30,51 @@ The substring with start index = 2 is "ab", which is an anagram of "ab".
3030
* @param {string} p
3131
* @return {number[]}
3232
*/
33-
var findAnagrams = function(s, p) {
34-
if(s.length < p.length) { return [] }
33+
var findAnagrams = function(s, p) {
34+
if(s.length < p.length) { return []; }
3535

3636
let start = 0;
3737
let end = p.length - 1;
3838
let hashBuild = {};
3939
let countLeft = p.length;
40-
let anagrams = []
40+
let anagrams = [];
4141

4242
for(let e = 0; e < p.length; e++) {
43-
hashBuild[p[e]] = hashBuild[p[e]] !== undefined ? hashBuild[p[e]] + 1 : 1;
43+
hashBuild[p[e]] = hashBuild[p[e]] !== undefined ? hashBuild[p[e]] + 1 : 1;
4444
}
4545

4646
for(let i = start; i < end; i++) {
47-
if(hashBuild[s[i]] !== undefined) {
48-
hashBuild[s[i]] = hashBuild[s[i]] - 1;
49-
if(hashBuild[s[i]] >= 0) {
50-
countLeft--;
51-
}
47+
if(hashBuild[s[i]] !== undefined) {
48+
hashBuild[s[i]] = hashBuild[s[i]] - 1;
49+
if(hashBuild[s[i]] >= 0) {
50+
countLeft--;
5251
}
52+
}
5353
}
5454

5555
while(end < s.length) {
56-
// check left
57-
if(hashBuild[s[end]] !== undefined) {
58-
hashBuild[s[end]] = hashBuild[s[end]] - 1;
59-
if(hashBuild[s[end]] >= 0) {
60-
countLeft--;
61-
}
62-
if(countLeft == 0) {
63-
anagrams.push(start);
64-
}
56+
// check left
57+
if(hashBuild[s[end]] !== undefined) {
58+
hashBuild[s[end]] = hashBuild[s[end]] - 1;
59+
if(hashBuild[s[end]] >= 0) {
60+
countLeft--;
6561
}
62+
if(countLeft == 0) {
63+
anagrams.push(start);
64+
}
65+
}
6666

67-
// check right
68-
if(hashBuild[s[start]] !== undefined) {
69-
hashBuild[s[start]] = hashBuild[s[start]] + 1;
70-
if(hashBuild[s[start]] >= 1) {
71-
countLeft++;
72-
}
67+
// check right
68+
if(hashBuild[s[start]] !== undefined) {
69+
hashBuild[s[start]] = hashBuild[s[start]] + 1;
70+
if(hashBuild[s[start]] >= 1) {
71+
countLeft++;
7372
}
73+
}
7474

75-
// slide window
76-
end++;
77-
start++;
75+
// slide window
76+
end++;
77+
start++;
7878
}
7979

8080
return anagrams;

‎LeetcodeProblems/Algorithms/Find_Subarrays_With_Equal_Sum.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Note that even though the subarrays have the same content, the two subarrays are
3535
* @param {number[]} nums
3636
* @return {boolean}
3737
*/
38-
var findSubarrays = function (nums) {
38+
var findSubarrays = function (nums) {
3939
const sumsSeen = new Set();
4040

4141
for (let i = 0; i < nums.length - 1; i++) {

‎LeetcodeProblems/Algorithms/Happy_Number.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ Output: false
3333
* @return {boolean}
3434
*/
3535
var isHappy = function(n) {
36-
return checkHappyNumber(n);
36+
return checkHappyNumber(n);
3737
};
3838

3939
function checkHappyNumber(n){
40-
strNumber = n.toString();
41-
splitNumber = strNumber.split("");
42-
if(splitNumber.length <= 1){
43-
return (n <= 1)? true:false;
44-
}
45-
const digit = splitNumber.reduce((a,b)=> parseInt(a) + Math.pow(parseInt(b),2),0);
46-
return checkHappyNumber(digit)
40+
let strNumber = n.toString();
41+
let splitNumber = strNumber.split("");
42+
if(splitNumber.length <= 1){
43+
return (n <= 1)? true:false;
44+
}
45+
const digit = splitNumber.reduce((a,b)=> parseInt(a) + Math.pow(parseInt(b),2),0);
46+
return checkHappyNumber(digit);
4747
}
4848

4949
module.exports.isHappy = isHappy;

‎LeetcodeProblems/Algorithms/Longest_Common_Prefix.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Explanation: There is no common prefix among the input strings.
2121
* @param {string[]} strs
2222
* @return {string}
2323
*/
24-
var longestCommonPrefix = function(strs) {
24+
var longestCommonPrefix = function(strs) {
2525
if(strs.length === 0) return "";
2626

2727
return strs.reduce((result, curr)=>{
28-
let i = 0;
29-
while(result[i] && curr[i] && result[i] === curr[i]) i++;
30-
return result.slice(0, i);
28+
let i = 0;
29+
while(result[i] && curr[i] && result[i] === curr[i]) i++;
30+
return result.slice(0, i);
3131
});
3232
};
3333

‎LeetcodeProblems/Algorithms/Longest_Substring.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ s consists of English letters, digits, symbols and spaces.
3232
* @param {string} s
3333
* @return {number}
3434
*/
35-
var lengthOfLongestSubstring = function(s) {
36-
if(s.length == 0) { return 0 }
35+
var lengthOfLongestSubstring = function(s) {
36+
if(s.length == 0) { return 0; }
3737

3838
var repeatedChars = new Set();
3939
var maxLength = 1;
@@ -45,15 +45,15 @@ s consists of English letters, digits, symbols and spaces.
4545
while(end + 1 < s.length && start < s.length) {
4646
if(repeatedChars.has(s.charAt(end + 1))) {
4747
if(repeatedChars.has(s.charAt(start))) {
48-
currentMaxLength--;
49-
repeatedChars.delete(s.charAt(start))
48+
currentMaxLength--;
49+
repeatedChars.delete(s.charAt(start));
5050
}
51-
start++;
51+
start++;
5252
} else {
5353
repeatedChars.add(s.charAt(end + 1));
5454
currentMaxLength++;
5555
if(currentMaxLength > maxLength) {
56-
maxLength = currentMaxLength;
56+
maxLength = currentMaxLength;
5757
}
5858
end++;
5959
}

‎LeetcodeProblems/Algorithms/Max_Consecutive_Ones_III.js‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ var longestOnes = function(nums, k) {
2424
let end = 0;
2525
let maxWindow = 0;
2626
while(start < nums.length && end < nums.length) {
27-
if(k > 0 || nums[end] == 1) {
28-
if(nums[end] == 0) { k--; }
29-
maxWindow = Math.max(maxWindow, end - start + 1);
30-
end++;
31-
} else { // k = 0 and nums[end] == 0
32-
while(k == 0 && start < nums.length) {
33-
if(nums[start] == 0) {
34-
k++;
35-
}
36-
start++;
37-
}
27+
if(k > 0 || nums[end] == 1) {
28+
if(nums[end] == 0) { k--; }
29+
maxWindow = Math.max(maxWindow, end - start + 1);
30+
end++;
31+
} else { // k = 0 and nums[end] == 0
32+
while(k == 0 && start < nums.length) {
33+
if(nums[start] == 0) {
34+
k++;
35+
}
36+
start++;
3837
}
38+
}
3939
}
4040

4141
return maxWindow;

‎LeetcodeProblems/Algorithms/Maximise_Hour_Glass_Sum.js‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,20 @@ Explanation: There is only one hourglass in the matrix, with the sum: 1 + 2 + 3
3131
* @param {number[][]} grid
3232
* @return {number}
3333
*/
34-
var maxSum = function(grid) {
34+
var maxSum = function(grid) {
3535
const m = grid.length;
3636
const n = grid[0].length;
3737
if(m<3 || n < 3) {
38-
return 0;
38+
return 0;
3939
}
4040
let max = 0;
4141
for(let i = 0; i<m-2; i++)
42-
for(let j = 0; j<n-2;j++)
43-
{
44-
let cur = grid[i][j] + grid[i][j+1] + grid[i][j+2] + grid[i+1][j+1] + grid[i+2][j] + grid[i+2][j+1] + grid[i+2][j+2];
45-
max = Math.max(cur, max);
46-
}
42+
for(let j = 0; j<n-2;j++)
43+
{
44+
let cur = grid[i][j] + grid[i][j+1] + grid[i][j+2] + grid[i+1][j+1] + grid[i+2][j] + grid[i+2][j+1] + grid[i+2][j+2];
45+
max = Math.max(cur, max);
46+
}
4747
return max;
48-
};
48+
};
49+
50+
module.exports.maxSum = maxSum;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /