Skip to content

Commit acb679b

Browse files
Rename problems and fix identation
1 parent b19d63c commit acb679b

31 files changed

+189
-255
lines changed
File renamed without changes.

LeetcodeProblems/CoinChange.js renamed to LeetcodeProblems/Coin_Change.js

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,20 @@
11
/*
2+
Coin Change
3+
https://leetcode.com/problems/coin-change/
24
3-
https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/description/
4-
5-
862. Shortest Subarray with Sum at Least K
6-
Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K.
7-
8-
If there is no non-empty subarray with sum at least K, return -1.
9-
10-
5+
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.
116
127
Example 1:
138
14-
Input: A = [1], K = 1
15-
Output: 1
9+
Input: coins = [1, 2, 5], amount = 11
10+
Output: 3
11+
Explanation: 11 = 5 + 5 + 1
1612
Example 2:
1713
18-
Input: A = [1,2], K = 4
14+
Input: coins = [2], amount = 3
1915
Output: -1
20-
Example 3:
21-
22-
Input: A = [2,-1,2], K = 3
23-
Output: 3
24-
25-
2616
Note:
27-
28-
1 <= A.length <= 50000
29-
-10 ^ 5 <= A[i] <= 10 ^ 5
30-
1 <= K <= 10 ^ 9
31-
*/
32-
33-
34-
/*
35-
Tree for solution
36-
37-
38-
[pos, countOfNumbers, K]
39-
[pos + 1, countOfNumbers, K] [pos + 1, countOfNumbers + 1, K - nums[pos]] [pos, countOfNumbers + 1, K - nums[pos]]
40-
...
41-
42-
[0, 0, 11] // [pos, countOfNumbers, K]
43-
/ | \
44-
[1, 0, 11] [1, 1, 10] [0, 1, 10]
45-
/ | \ / | \ / | \
46-
[2, 0, 11] [2, 1, 9] [1, 1, 9] [2, 0, 10] [2, 2, 8] [1, 2, 8] [1, 1, 10] [1, 2, 9] [0, 2, 9]
47-
...
17+
You may assume that you have an infinite number of each kind of coin.
4818
*/
4919

5020
// Solution 3
@@ -132,24 +102,7 @@ var min = function(a, b, c) {
132102
return (b < c) ? b : c;
133103
}
134104

135-
136105
function main() {
137-
// console.log("-------------");
138-
// console.log("Approach 1")
139-
// console.log(coinChange1([], 3));
140-
// console.log(coinChange1([2], 3));
141-
// console.log(coinChange1([1, 2, 5], 11));
142-
// console.log(coinChange1([3,7,405,436], 8839));
143-
// // console.log(coinChange1([370,417,408,156,143,434,168,83,177,280,117], 9953)); takes forever
144-
145-
// console.log("-------------");
146-
// console.log("Approach 2")
147-
// console.log(coinChange2([], 3));
148-
// console.log(coinChange2([2], 3));
149-
// console.log(coinChange2([1, 2, 5], 11));
150-
// console.log(coinChange2([3,7,405,436], 8839));
151-
// console.log(coinChange2([370,417,408,156,143,434,168,83,177,280,117], 9953));
152-
153106
console.log("-------------");
154107
console.log("Approach 3")
155108
console.log(coinChange3([], 3));

LeetcodeProblems/design-circular-deque.js renamed to LeetcodeProblems/Design_Circular_Deque.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
Design Circular Deque
23
https://leetcode.com/problems/design-circular-deque/description/
34
45
Design your implementation of the circular double-ended queue (deque).
@@ -145,5 +146,5 @@ var main = function(){
145146
console.log(obj.insertFront(4));
146147
console.log(obj.getFront());
147148
}
148-
main();
149+
149150
module.exports.main = main;

LeetcodeProblems/Escape-The-Ghosts.js renamed to LeetcodeProblems/Escape_The_Ghosts.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/*
2+
Escape The Ghosts
23
https://leetcode.com/problems/escape-the-ghosts/description/
34
4-
789. Escape The Ghosts
5-
65
You are playing a simplified Pacman game. You start at the point (0, 0), and your destination is (target[0], target[1]). There are several ghosts on the map, the i-th ghost starts at (ghosts[i][0], ghosts[i][1]).
76
87
Each turn, you and all ghosts simultaneously *may* move in one of 4 cardinal directions: north, east, west, or south, going from the previous point to a new point 1 unit of distance away.

LeetcodeProblems/FloodFill.js renamed to LeetcodeProblems/Flood_Fill.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
Flood Fill
23
https://leetcode.com/problems/flood-fill/description/
34
45
An image is represented by a 2-D array of integers, each integer representing the pixel value of the image (from 0 to 65535).

LeetcodeProblems/GenerateParentheses.js renamed to LeetcodeProblems/Generate_Parentheses.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
Generate Parentheses
23
https://leetcode.com/problems/generate-parentheses
34
45
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
@@ -31,7 +32,6 @@ var generateParenthesesApproach1 = function(n) {
3132
@param {string} leftParenthesis Amount for parenthesis left to be added.
3233
@param {[string]} sol array that contains the solution found so far.
3334
*/
34-
3535
var genParAux = function(str, position, leftParentheses, sol) {
3636
if(position === str.length) {
3737
var ret = str + ")".repeat(leftParentheses);

LeetcodeProblems/GroupAnagrams.js renamed to LeetcodeProblems/Group_Anagrams.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
Group Anagrams
23
https://leetcode.com/problems/group-anagrams/description/
34
45
Given an array of strings, group anagrams together.

LeetcodeProblems/linked-list-cycle-ii.js renamed to LeetcodeProblems/Linked_List_Cycle_II.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
Linked List Cycle
23
https://leetcode.com/problems/linked-list-cycle-ii/description/
34
45
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
@@ -9,6 +10,7 @@ Follow up:
910
Can you solve it without using extra space?
1011
*/
1112

13+
var ListNode = require('../utilsClasses/ListNode').ListNode;
1214

1315
// Optimal solution
1416
/**
@@ -59,15 +61,9 @@ var main = function() {
5961
const head = buildCycle();
6062
console.log(detectCycle(head));
6163
}
62-
main();
63-
64-
function ListNode(val) {
65-
this.val = val;
66-
this.next = null;
67-
}
6864

6965
function buildCycle() {
70-
var node1 = new ListNode(1);
66+
var node1 = ListNode.linkenList([1,2,3,4,5]);
7167
var node2 = new ListNode(2);
7268
var node3 = new ListNode(3);
7369
var node4 = new ListNode(4);
@@ -78,13 +74,7 @@ function buildCycle() {
7874
node3.next = node4;
7975
node4.next = node5;
8076
node5.next = node2;
81-
82-
/* 1 -> 2 -> 3 -> 4 -> 5
83-
\ /
84-
- - - - -
85-
*/
8677
return node1;
8778
}
8879

89-
main();
9080
module.exports.main = main;

LeetcodeProblems/Longest_Consecutive_Sequence.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
22
Longest Consecutive Sequence
3-
43
https://leetcode.com/problems/longest-consecutive-sequence/
54
65
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
@@ -53,7 +52,6 @@ var longestConsecutive = function(nums) {
5352
return cons;
5453
};
5554

56-
5755
var main = function() {
5856
console.log(longestConsecutive([100, 1, 200, 3, 2, 400, 201]));
5957
console.log(longestConsecutive([1,2,3,4, 100, 1, 200, 3, 2, 400, 201]));

0 commit comments

Comments
 (0)