@@ -239,48 +239,48 @@ function maxmiumScore(cards: number[], cnt: number): number {
239239
240240``` swift
241241class Solution {
242- func maxmiumScore (_ cards : [Int ], _ cnt : Int ) -> Int {
242+ func maximumScore (_ cards : [Int ], _ cnt : Int ) -> Int {
243243 let sortedCards = cards.sorted ()
244244 let n = sortedCards.count
245245 var ans = 0
246-
246+
247247 for i in 0 ..< cnt {
248248 ans += sortedCards[n - i - 1 ]
249249 }
250-
250+
251251 if ans % 2 == 0 {
252252 return ans
253253 }
254-
254+
255255 var smallestOddInside = Int .max
256256 var smallestEvenInside = Int .max
257257 var largestOddOutside = Int .min
258258 var largestEvenOutside = Int .min
259-
259+
260260 for i in (n - cnt)..< n {
261261 if sortedCards[i] % 2 == 1 {
262262 smallestOddInside = min (smallestOddInside, sortedCards[i])
263263 } else {
264264 smallestEvenInside = min (smallestEvenInside, sortedCards[i])
265265 }
266266 }
267-
267+
268268 for i in 0 ..< (n - cnt) {
269269 if sortedCards[i] % 2 == 1 {
270270 largestOddOutside = max (largestOddOutside, sortedCards[i])
271271 } else {
272272 largestEvenOutside = max (largestEvenOutside, sortedCards[i])
273273 }
274274 }
275-
275+
276276 var maxScore = -1
277277 if smallestOddInside != Int .max && largestEvenOutside != Int .min {
278278 maxScore = max (maxScore, ans - smallestOddInside + largestEvenOutside)
279279 }
280280 if smallestEvenInside != Int .max && largestOddOutside != Int .min {
281281 maxScore = max (maxScore, ans - smallestEvenInside + largestOddOutside)
282282 }
283-
283+
284284 return maxScore >= 0 ? maxScore : 0
285285 }
286286}
0 commit comments