Skip to content

Commit b66e318

Browse files
author
Jacopo
committed
Filters the potential change arrays for only the ones which add up to the exact value
1 parent 8080f27 commit b66e318

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

MinimumCoinChange/Sources/MinimumCoinChange.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ public struct MinimumCoinChange {
6464
if value - coin >= 0 {
6565
var potentialChange: [Int] = [coin]
6666
potentialChange.append(contentsOf: _changeDynamic(value - coin))
67-
potentialChangeArray.append(potentialChange)
67+
68+
if potentialChange.reduce(0, +) == value {
69+
potentialChangeArray.append(potentialChange)
70+
}
6871
}
6972
}
7073

0 commit comments

Comments
 (0)