Skip to content

Tests #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 6, 2020
25 changes: 1 addition & 24 deletions LeetcodeProblems/3Sum.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ A solution set is:
[-1, -1, 2]
]
*/
const assert = require('assert');

/**
* @param {number[]} nums
Expand Down Expand Up @@ -49,26 +48,4 @@ var threeSum = function(nums) {
return ret;
};

var main = function() {
test();
}

var test = function () {
assert.deepEqual(threeSum([]), []);
assert.deepEqual(threeSum([0]), []);
assert.deepEqual(threeSum([0, 0]), []);
assert.deepEqual(
threeSum([0, 0, 0]),
[[0, 0, 0]]
);
assert.deepEqual(
threeSum([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),
[[0, 0, 0]]
);
assert.deepEqual(
threeSum([-1, 0, 1, 2, -1, -4]),
[ [ -1, 2, -1 ], [ 0, 1, -1 ] ]
);
}

module.exports.main = main;
module.exports.threeSum = threeSum;
33 changes: 2 additions & 31 deletions LeetcodeProblems/Add_Two_Numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ Explanation: 342 + 465 = 807.
* this.next = null;
* }
*/
const assert = require('assert');
const ListNodeTestHelper = require('../utilsClasses/ListNodeTestHelper');
var ListNode = require('../UtilsClasses/ListNode').ListNode;

/**
* @param {ListNode} l1
* @param {ListNode} l2
Expand Down Expand Up @@ -64,31 +62,4 @@ var addTwoNumbers = function(l1, l2) {
return head;
};

var main = function() {
test();
}

function test() {
const list1 = ListNode.linkenList([1,2,3,4]);
const list2 = ListNode.linkenList([1,2,3,4]);
ListNodeTestHelper.assertList(
addTwoNumbers(list1, list2),
[2, 4, 6, 8]
);

const list3 = ListNode.linkenList([1]);
const list4 = ListNode.linkenList([1,2]);
ListNodeTestHelper.assertList(
addTwoNumbers(list3, list4),
[2, 2]
);

const list5 = ListNode.linkenList([]);
const list6 = ListNode.linkenList([1,2]);
ListNodeTestHelper.assertList(
addTwoNumbers(list5, list6),
[1, 2]
);
}

module.exports.main = main;
module.exports.addTwoNumbers = addTwoNumbers;
19 changes: 1 addition & 18 deletions LeetcodeProblems/Award_Budget_Cuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ Constraints:

[output] double
*/
const assert = require('assert');

var cutAwardBadges = function(nums, newBadge) {
var currentBadge = 0;
for(var i = 0; i < nums.length; i++)
Expand Down Expand Up @@ -66,19 +64,4 @@ var findCap = function(nums, currentBadge, newBadge) {
return nums[iter] + (-diff) / iter;
}

var main = function() {
test();
}

function test() {
assert.deepEqual(
cutAwardBadges([2, 100, 50, 120, 1000], 190),
[ 47, 47, 47, 47, 2 ]
);
assert.deepEqual(
cutAwardBadges([2, 100, 50, 120, 1000], 5),
[ 1, 1, 1, 1, 1 ]
);
}

module.exports.main = main;
module.exports.cutAwardBadges = cutAwardBadges;
20 changes: 2 additions & 18 deletions LeetcodeProblems/Backspace_String_Compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Follow up:

Can you solve it in O(N) time and O(1) space?
*/
const assert = require('assert');

/**
* @param {string} S
Expand Down Expand Up @@ -106,20 +105,5 @@ var backspaceCompare2 = function(S, T) {
return stackS.length === 0 && stackT.length === 0;
};

var main = function() {
test();
}

function test() {
assert.equal(backspaceCompare("ab#c", "ad#c"), true); // true
assert.equal(backspaceCompare("ab##", "c#d#"), true); // true
assert.equal(backspaceCompare("a##c", "#a#c"), true); // true
assert.equal(backspaceCompare("a#c", "b"), false); // false

assert.equal(backspaceCompare2("ab#c", "ad#c"), true); // true
assert.equal(backspaceCompare2("ab##", "c#d#"), true); // true
assert.equal(backspaceCompare2("a##c", "#a#c"), true); // true
assert.equal(backspaceCompare2("a#c", "b"), false); // false
}

module.exports.main = main;
module.exports.backspaceCompare = backspaceCompare;
module.exports.backspaceCompare2 = backspaceCompare2;
12 changes: 1 addition & 11 deletions LeetcodeProblems/Best_Time_To_Buy_And_Sell_Stock_II.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Input: [7,6,4,3,1]
Output: 0
Explanation: In this case, no transaction is done, i.e. max profit = 0.
*/
const assert = require('assert');

/**
* @param {number[]} prices
Expand Down Expand Up @@ -56,13 +55,4 @@ var maxProfit = function(prices) {
return profit;
};

var main = function() {
test();
}

function test() {
assert.equal(maxProfit([7,1,5,3,6,4]), 7);
assert.equal(maxProfit([7,1,5,3320,6,4]), 3319);
}

module.exports.main = main;
module.exports.maxProfit = maxProfit;
12 changes: 1 addition & 11 deletions LeetcodeProblems/Binary_Gap.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Explanation:
8 in binary is 0b1000.
There aren't any consecutive pairs of 1's in the binary representation of 8, so we return 0.
*/
const assert = require('assert');

/**
* @param {number} N
Expand All @@ -61,13 +60,4 @@ var binaryGap = function(N) {
return maxDist;
};

var main = function() {
test();
}

function test() {
assert.equal(binaryGap(22), 2); // 10110
assert.equal(binaryGap(8), 0); // 1000
}

module.exports.main = main;
module.exports.binaryGap = binaryGap;
1 change: 0 additions & 1 deletion LeetcodeProblems/Clone_Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ You don't need to understand the serialization to solve the problem.
* }
*/


// SOLUTION 1 Using DFS
/**
* @param {UndirectedGraphNode} graph
Expand Down
15 changes: 1 addition & 14 deletions LeetcodeProblems/Coin_Change.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Output: -1
Note:
You may assume that you have an infinite number of each kind of coin.
*/
const assert = require('assert');

// Solution 3
var coinChange = function(coins, amount) {
Expand Down Expand Up @@ -102,16 +101,4 @@ var min = function(a, b, c) {
return (b < c) ? b : c;
}

function main() {
test();
}

function test() {
assert.equal(coinChange([], 3), -1);
assert.equal(coinChange([2], 3), -1);
assert.equal(coinChange([1, 2, 5], 11), 3);
assert.equal(coinChange([3, 7, 405, 436], 8839), 25);
assert.equal(coinChange([370, 417, 408, 156, 143, 434, 168, 83, 177, 280, 117], 9953), 24);
}

module.exports.main = main;
module.exports.coinChange = coinChange;
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ Return the following binary tree:
* this.left = this.right = null;
* }
*/
const assert = require('assert');

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

/**
Expand Down Expand Up @@ -59,12 +57,4 @@ var buildTreeAux = function(preorder, pl, ph, inorder, il, ih) {
return ret;
}

var main = function() {
test();
}

function test() {
console.log(buildTree([3,9,20,15,7], [9,3,15,20,7]));
}

module.exports.main = main
module.exports.buildTree = buildTree
26 changes: 3 additions & 23 deletions LeetcodeProblems/Deletion_Distance.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ output: 9
input: str1 = "", str2 = ""
output: 0
*/
const assert = require('assert');

// Solution 3 Using DP
var deletionDistanceDP = function(str1, str2) {
Expand Down Expand Up @@ -107,25 +106,6 @@ var min = function(a, b) {
return (a < b) ? a : b;
}

function main() {
test();
}

function test() {
assert.equal(deletionDistance("dog", "frog"), 3);
assert.equal(deletionDistance("some", "some"), 0);
assert.equal(deletionDistance("some", "thing"), 9);
assert.equal(deletionDistance("", ""), 0);

assert.equal(deletionDistance2("dog", "frog"), 3);
assert.equal(deletionDistance2("some", "some"), 0);
assert.equal(deletionDistance2("some", "thing"), 9);
assert.equal(deletionDistance2("", ""), 0);

assert.equal(deletionDistanceDP("dog", "frog"), 3);
assert.equal(deletionDistanceDP("some", "some"), 0);
assert.equal(deletionDistanceDP("some", "thing"), 9);
assert.equal(deletionDistanceDP("", ""), 0);
}

module.exports.main = main
module.exports.deletionDistance = deletionDistance;
module.exports.deletionDistance2 = deletionDistance2;
module.exports.deletionDistanceDP = deletionDistanceDP;
20 changes: 1 addition & 19 deletions LeetcodeProblems/Design_Circular_Deque.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ All values will be in the range of [0, 1000].
The number of operations will be in the range of [1, 1000].
Please do not use the built-in Deque library.
*/
const assert = require('assert');

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

var main = function(){
test();
};

var test = function() {
const obj = new MyCircularDeque(3);
assert.equal(obj.insertLast(1), true);
assert.equal(obj.insertLast(2), true);
assert.equal(obj.insertFront(3), true);
assert.equal(obj.insertFront(4), false);
assert.equal(obj.getRear(), 2);
assert.equal(obj.isFull(), true);
assert.equal(obj.deleteLast(), true);
assert.equal(obj.insertFront(4), true);
assert.equal(obj.getFront(), 4);
}

module.exports.main = main;
module.exports.MyCircularDeque = MyCircularDeque;
16 changes: 2 additions & 14 deletions LeetcodeProblems/Edit_Distance.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ enention -> exention (replace 'n' with 'x')
exention -> exection (replace 'n' with 'c')
exection -> execution (insert 'u')
*/
const assert = require('assert');

// Optimal solution
var minDistance = function(word1, word2) {
Expand Down Expand Up @@ -98,16 +97,5 @@ var min = function(a, b, c) {
return (b < c) ? b : c;
}

var main = function() {
test();
}

function test() {
assert.equal(minDistance("ros", "horse"), 3);
assert.equal(minDistance("intention", "execution"), 5);

assert.equal(minDistance2("ros", "horse"), 3);
assert.equal(minDistance2("intention", "execution"), 5);
}

module.exports.main = main;
module.exports.minDistance = minDistance;
module.exports.minDistance2 = minDistance2;
13 changes: 1 addition & 12 deletions LeetcodeProblems/Escape_The_Ghosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Note:
All points have coordinates with absolute value <= 10000.
The number of ghosts will not exceed 100.
*/
const assert = require('assert');

/**
* @param {number[][]} ghosts
Expand All @@ -60,14 +59,4 @@ var getDistance = function(a, b) {
return horizontalMoves + verticalMoves;
}

var main = function() {
test();
}

function test() {
assert.equal(escapeGhosts([[1, 0], [0, 3]], [0, 1]), true);
assert.equal(escapeGhosts([[1, 0]], [2, 0]), false);
assert.equal(escapeGhosts([[2, 0]], [1, 0]), true);
}

module.exports.main = main
module.exports.escapeGhosts = escapeGhosts;
14 changes: 1 addition & 13 deletions LeetcodeProblems/Flood_Fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ The length of image and image[0] will be in the range [1, 50].
The given starting pixel will satisfy 0 <= sr < image.length and 0 <= sc < image[0].length.
The value of each color in image[i][j] and newColor will be an integer in [0, 65535].
*/
const assert = require('assert');

var floodFill = function(image, sr, sc, newColor) {
var oldColor = image[sr][sc];
Expand All @@ -53,15 +52,4 @@ var floodFill = function(image, sr, sc, newColor) {
return image;
};

function main() {
test();
}

function test() {
assert.deepEqual(
[ [ 2, 2, 2 ], [ 2, 2, 0 ], [ 2, 0, 1 ] ],
floodFill([[1,1,1],[1,1,0],[1,0,1]], 1, 1, 2)
);
}

module.exports.main = main;
module.exports.floodFill = floodFill;
Loading