mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
Merge branches 'issue-102-rabin-karp-fix' and 'master' of https://github.com/trekhleb/javascript-algorithms into issue-102-rabin-karp-fix
This commit is contained in:
@@ -10,7 +10,7 @@ export default function kruskal(graph) {
|
||||
// It should fire error if graph is directed since the algorithm works only
|
||||
// for undirected graphs.
|
||||
if (graph.isDirected) {
|
||||
throw new Error('Prim\'s algorithms works only for undirected graphs');
|
||||
throw new Error('Kruskal\'s algorithms works only for undirected graphs');
|
||||
}
|
||||
|
||||
// Init new graph that will contain minimum spanning tree of original graph.
|
||||
|
||||
@@ -15,20 +15,20 @@ function combinationSumRecursive(
|
||||
) {
|
||||
if (remainingSum < 0) {
|
||||
// By adding another candidate we've gone below zero.
|
||||
// This would mean that last candidate was not acceptable.
|
||||
// This would mean that the last candidate was not acceptable.
|
||||
return finalCombinations;
|
||||
}
|
||||
|
||||
if (remainingSum === 0) {
|
||||
// In case if after adding the previous candidate out remaining sum
|
||||
// became zero we need to same current combination since it is one
|
||||
// of the answer we're looking for.
|
||||
// If after adding the previous candidate our remaining sum
|
||||
// became zero - we need to save the current combination since it is one
|
||||
// of the answers we're looking for.
|
||||
finalCombinations.push(currentCombination.slice());
|
||||
|
||||
return finalCombinations;
|
||||
}
|
||||
|
||||
// In case if we haven't reached zero yet let's continue to add all
|
||||
// If we haven't reached zero yet let's continue to add all
|
||||
// possible candidates that are left.
|
||||
for (let candidateIndex = startFrom; candidateIndex < candidates.length; candidateIndex += 1) {
|
||||
const currentCandidate = candidates[candidateIndex];
|
||||
|
||||
Reference in New Issue
Block a user