Skip to content

Commit 4a82a5b

Browse files
remove uselessrequires
1 parent 49438a3 commit 4a82a5b

Some content is hidden

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

52 files changed

+56
-205
lines changed

LeetcodeProblems/3Sum.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ A solution set is:
1818
[-1, -1, 2]
1919
]
2020
*/
21-
const assert = require('assert');
2221

2322
/**
2423
* @param {number[]} nums
@@ -49,26 +48,4 @@ var threeSum = function(nums) {
4948
return ret;
5049
};
5150

52-
var main = function() {
53-
test();
54-
}
55-
56-
var test = function () {
57-
assert.deepEqual(threeSum([]), []);
58-
assert.deepEqual(threeSum([0]), []);
59-
assert.deepEqual(threeSum([0, 0]), []);
60-
assert.deepEqual(
61-
threeSum([0, 0, 0]),
62-
[[0, 0, 0]]
63-
);
64-
assert.deepEqual(
65-
threeSum([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),
66-
[[0, 0, 0]]
67-
);
68-
assert.deepEqual(
69-
threeSum([-1, 0, 1, 2, -1, -4]),
70-
[ [ -1, 2, -1 ], [ 0, 1, -1 ] ]
71-
);
72-
}
73-
74-
module.exports.main = main;
51+
module.exports.threeSum = threeSum;

LeetcodeProblems/Add_Two_Numbers.js

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ Explanation: 342 + 465 = 807.
2121
* this.next = null;
2222
* }
2323
*/
24-
const assert = require('assert');
25-
const ListNodeTestHelper = require('../utilsClasses/ListNodeTestHelper');
2624
var ListNode = require('../UtilsClasses/ListNode').ListNode;
27-
25+
2826
/**
2927
* @param {ListNode} l1
3028
* @param {ListNode} l2
@@ -64,31 +62,4 @@ var addTwoNumbers = function(l1, l2) {
6462
return head;
6563
};
6664

67-
var main = function() {
68-
test();
69-
}
70-
71-
function test() {
72-
const list1 = ListNode.linkenList([1,2,3,4]);
73-
const list2 = ListNode.linkenList([1,2,3,4]);
74-
ListNodeTestHelper.assertList(
75-
addTwoNumbers(list1, list2),
76-
[2, 4, 6, 8]
77-
);
78-
79-
const list3 = ListNode.linkenList([1]);
80-
const list4 = ListNode.linkenList([1,2]);
81-
ListNodeTestHelper.assertList(
82-
addTwoNumbers(list3, list4),
83-
[2, 2]
84-
);
85-
86-
const list5 = ListNode.linkenList([]);
87-
const list6 = ListNode.linkenList([1,2]);
88-
ListNodeTestHelper.assertList(
89-
addTwoNumbers(list5, list6),
90-
[1, 2]
91-
);
92-
}
93-
94-
module.exports.main = main;
65+
module.exports.addTwoNumbers = addTwoNumbers;

LeetcodeProblems/Award_Budget_Cuts.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ Constraints:
2929
3030
[output] double
3131
*/
32-
const assert = require('assert');
33-
3432
var cutAwardBadges = function(nums, newBadge) {
3533
var currentBadge = 0;
3634
for(var i = 0; i < nums.length; i++)
@@ -66,19 +64,4 @@ var findCap = function(nums, currentBadge, newBadge) {
6664
return nums[iter] + (-diff) / iter;
6765
}
6866

69-
var main = function() {
70-
test();
71-
}
72-
73-
function test() {
74-
assert.deepEqual(
75-
cutAwardBadges([2, 100, 50, 120, 1000], 190),
76-
[ 47, 47, 47, 47, 2 ]
77-
);
78-
assert.deepEqual(
79-
cutAwardBadges([2, 100, 50, 120, 1000], 5),
80-
[ 1, 1, 1, 1, 1 ]
81-
);
82-
}
83-
84-
module.exports.main = main;
67+
module.exports.cutAwardBadges = cutAwardBadges;

LeetcodeProblems/Backspace_String_Compare.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Follow up:
3131
3232
Can you solve it in O(N) time and O(1) space?
3333
*/
34-
const assert = require('assert');
3534

3635
/**
3736
* @param {string} S
@@ -106,20 +105,5 @@ var backspaceCompare2 = function(S, T) {
106105
return stackS.length === 0 && stackT.length === 0;
107106
};
108107

109-
var main = function() {
110-
test();
111-
}
112-
113-
function test() {
114-
assert.equal(backspaceCompare("ab#c", "ad#c"), true); // true
115-
assert.equal(backspaceCompare("ab##", "c#d#"), true); // true
116-
assert.equal(backspaceCompare("a##c", "#a#c"), true); // true
117-
assert.equal(backspaceCompare("a#c", "b"), false); // false
118-
119-
assert.equal(backspaceCompare2("ab#c", "ad#c"), true); // true
120-
assert.equal(backspaceCompare2("ab##", "c#d#"), true); // true
121-
assert.equal(backspaceCompare2("a##c", "#a#c"), true); // true
122-
assert.equal(backspaceCompare2("a#c", "b"), false); // false
123-
}
124-
125-
module.exports.main = main;
108+
module.exports.backspaceCompare = backspaceCompare;
109+
module.exports.backspaceCompare2 = backspaceCompare2;

LeetcodeProblems/Best_Time_To_Buy_And_Sell_Stock_II.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ Input: [7,6,4,3,1]
2727
Output: 0
2828
Explanation: In this case, no transaction is done, i.e. max profit = 0.
2929
*/
30-
const assert = require('assert');
3130

3231
/**
3332
* @param {number[]} prices
@@ -65,4 +64,4 @@ function test() {
6564
assert.equal(maxProfit([7,1,5,3320,6,4]), 3319);
6665
}
6766

68-
module.exports.main = main;
67+
module.exports.maxProfit = maxProfit;

LeetcodeProblems/Binary_Gap.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Explanation:
3636
8 in binary is 0b1000.
3737
There aren't any consecutive pairs of 1's in the binary representation of 8, so we return 0.
3838
*/
39-
const assert = require('assert');
4039

4140
/**
4241
* @param {number} N
@@ -61,13 +60,4 @@ var binaryGap = function(N) {
6160
return maxDist;
6261
};
6362

64-
var main = function() {
65-
test();
66-
}
67-
68-
function test() {
69-
assert.equal(binaryGap(22), 2); // 10110
70-
assert.equal(binaryGap(8), 0); // 1000
71-
}
72-
73-
module.exports.main = main;
63+
module.exports.binaryGap = binaryGap;

LeetcodeProblems/Clone_Graph.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ You don't need to understand the serialization to solve the problem.
4040
* }
4141
*/
4242

43-
4443
// SOLUTION 1 Using DFS
4544
/**
4645
* @param {UndirectedGraphNode} graph

LeetcodeProblems/Coin_Change.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Output: -1
1818
Note:
1919
You may assume that you have an infinite number of each kind of coin.
2020
*/
21-
const assert = require('assert');
2221

2322
// Solution 3
2423
var coinChange = function(coins, amount) {
@@ -102,16 +101,4 @@ var min = function(a, b, c) {
102101
return (b < c) ? b : c;
103102
}
104103

105-
function main() {
106-
test();
107-
}
108-
109-
function test() {
110-
assert.equal(coinChange([], 3), -1);
111-
assert.equal(coinChange([2], 3), -1);
112-
assert.equal(coinChange([1, 2, 5], 11), 3);
113-
assert.equal(coinChange([3, 7, 405, 436], 8839), 25);
114-
assert.equal(coinChange([370, 417, 408, 156, 143, 434, 168, 83, 177, 280, 117], 9953), 24);
115-
}
116-
117-
module.exports.main = main;
104+
module.exports.coinChange = coinChange;

LeetcodeProblems/Construct_Binary_Tree_from_Preorder_and_Inorder_Traversal.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ Return the following binary tree:
2727
* this.left = this.right = null;
2828
* }
2929
*/
30-
const assert = require('assert');
31-
3230
var TreeNode = require('../UtilsClasses/TreeNode').TreeNode;
3331

3432
/**
@@ -59,12 +57,4 @@ var buildTreeAux = function(preorder, pl, ph, inorder, il, ih) {
5957
return ret;
6058
}
6159

62-
var main = function() {
63-
test();
64-
}
65-
66-
function test() {
67-
console.log(buildTree([3,9,20,15,7], [9,3,15,20,7]));
68-
}
69-
70-
module.exports.main = main
60+
module.exports.buildTree = buildTree

LeetcodeProblems/Deletion_Distance.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ output: 9
1818
input: str1 = "", str2 = ""
1919
output: 0
2020
*/
21-
const assert = require('assert');
2221

2322
// Solution 3 Using DP
2423
var deletionDistanceDP = function(str1, str2) {
@@ -128,4 +127,7 @@ function test() {
128127
assert.equal(deletionDistanceDP("", ""), 0);
129128
}
130129

131-
module.exports.main = main
130+
module.exports.deletionDistance = deletionDistance;
131+
module.exports.deletionDistance2 = deletionDistance2;
132+
module.exports.deletionDistanceDP = deletionDistanceDP;
133+

LeetcodeProblems/Design_Circular_Deque.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ All values will be in the range of [0, 1000].
3535
The number of operations will be in the range of [1, 1000].
3636
Please do not use the built-in Deque library.
3737
*/
38-
const assert = require('assert');
3938

4039
/**
4140
* Initialize your data structure here. Set the size of the deque to be k.
@@ -132,21 +131,4 @@ MyCircularDeque.prototype.isFull = function() {
132131
return this.queue.length === this.maxSize;
133132
};
134133

135-
var main = function(){
136-
test();
137-
};
138-
139-
var test = function() {
140-
const obj = new MyCircularDeque(3);
141-
assert.equal(obj.insertLast(1), true);
142-
assert.equal(obj.insertLast(2), true);
143-
assert.equal(obj.insertFront(3), true);
144-
assert.equal(obj.insertFront(4), false);
145-
assert.equal(obj.getRear(), 2);
146-
assert.equal(obj.isFull(), true);
147-
assert.equal(obj.deleteLast(), true);
148-
assert.equal(obj.insertFront(4), true);
149-
assert.equal(obj.getFront(), 4);
150-
}
151-
152-
module.exports.main = main;
134+
module.exports.MyCircularDeque = MyCircularDeque;

LeetcodeProblems/Edit_Distance.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ enention -> exention (replace 'n' with 'x')
2828
exention -> exection (replace 'n' with 'c')
2929
exection -> execution (insert 'u')
3030
*/
31-
const assert = require('assert');
3231

3332
// Optimal solution
3433
var minDistance = function(word1, word2) {
@@ -98,16 +97,5 @@ var min = function(a, b, c) {
9897
return (b < c) ? b : c;
9998
}
10099

101-
var main = function() {
102-
test();
103-
}
104-
105-
function test() {
106-
assert.equal(minDistance("ros", "horse"), 3);
107-
assert.equal(minDistance("intention", "execution"), 5);
108-
109-
assert.equal(minDistance2("ros", "horse"), 3);
110-
assert.equal(minDistance2("intention", "execution"), 5);
111-
}
112-
113-
module.exports.main = main;
100+
module.exports.minDistance = minDistance;
101+
module.exports.minDistance2 = minDistance2;

LeetcodeProblems/Escape_The_Ghosts.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ Note:
3636
All points have coordinates with absolute value <= 10000.
3737
The number of ghosts will not exceed 100.
3838
*/
39-
const assert = require('assert');
4039

4140
/**
4241
* @param {number[][]} ghosts

LeetcodeProblems/Flood_Fill.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The length of image and image[0] will be in the range [1, 50].
2828
The given starting pixel will satisfy 0 <= sr < image.length and 0 <= sc < image[0].length.
2929
The value of each color in image[i][j] and newColor will be an integer in [0, 65535].
3030
*/
31-
const assert = require('assert');
31+
3232

3333
var floodFill = function(image, sr, sc, newColor) {
3434
var oldColor = image[sr][sc];

LeetcodeProblems/Group_Anagrams.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Note:
1818
All inputs will be in lowercase.
1919
The order of your output does not matter.
2020
*/
21-
const assert = require('assert');
21+
2222

2323
var groupAnagrams = function(strs) {
2424
var ret = [];

LeetcodeProblems/Implement_stack_using_queues.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ You must use only standard operations of a queue -- which means only push to bac
2323
Depending on your language, queue may not be supported natively. You may simulate a queue by using a list or deque (double-ended queue), as long as you use only standard operations of a queue.
2424
You may assume that all operations are valid (for example, no pop or top operations will be called on an empty stack).
2525
*/
26-
const assert = require('assert');
26+
2727
class MyStack {
2828
constructor() {
2929
this.q1 = [];

LeetcodeProblems/Kth_Largest_Element_in_an_Array.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Output: 4
1515
Note:
1616
You may assume k is always valid, 1 ≤ k ≤ array's length.
1717
*/
18-
const assert = require('assert');
18+
1919

2020
/**
2121
* @param {number[]} nums

LeetcodeProblems/Linked_List_Cycle_II.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Note: Do not modify the linked list.
99
Follow up:
1010
Can you solve it without using extra space?
1111
*/
12-
const assert = require('assert');
12+
1313
var ListNode = require('../UtilsClasses/ListNode').ListNode;
1414

1515
// Optimal solution

LeetcodeProblems/Longest_Consecutive_Sequence.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Input: [100, 4, 200, 1, 3, 2]
1212
Output: 4
1313
Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.
1414
*/
15-
const assert = require('assert');
15+
1616

1717
/**
1818
* @param {number[]} nums

LeetcodeProblems/Longest_Palindromic_Substring.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Example 2:
1414
Input: "cbbd"
1515
Output: "bb"
1616
*/
17-
const assert = require('assert');
17+
1818

1919
/**
2020
* @param {string} s

LeetcodeProblems/Lowest_Common_Ancestor_of_a_Binary_Tree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Note:
3333
All of the nodes' values will be unique.
3434
p and q are different and both values will exist in the binary tree.
3535
*/
36-
const assert = require('assert');
36+
3737

3838
var TreeNode = require('../UtilsClasses/TreeNode').TreeNode;
3939

0 commit comments

Comments
 (0)