Skip to content

Commit d5c9d17

Browse files
author
Jacopo
committed
Optimisation: removed double check if the winner change is valid
1 parent b66e318 commit d5c9d17

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

MinimumCoinChange/Sources/MinimumCoinChange.swift

+3-8
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ public struct MinimumCoinChange {
5656
return cached
5757
}
5858

59-
var change: [Int] = []
60-
6159
var potentialChangeArray: [[Int]] = []
6260

6361
for coin in sortedCoinSet {
@@ -73,14 +71,11 @@ public struct MinimumCoinChange {
7371

7472
if potentialChangeArray.count > 0 {
7573
let sortedPotentialChangeArray = potentialChangeArray.sorted(by: { $0.count < $1.count })
76-
change = sortedPotentialChangeArray[0]
74+
cache[value] = sortedPotentialChangeArray[0]
75+
return sortedPotentialChangeArray[0]
7776
}
7877

79-
if change.reduce(0, +) == value {
80-
cache[value] = change
81-
}
82-
83-
return change
78+
return []
8479
}
8580

8681
let change: [Int] = _changeDynamic(value)

0 commit comments

Comments
 (0)