File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 11class Solution {
2- func maxmiumScore ( _ cards: [ Int ] , _ cnt: Int ) -> Int {
2+ func maximumScore ( _ cards: [ Int ] , _ cnt: Int ) -> Int {
33 let sortedCards = cards. sorted ( )
44 let n = sortedCards. count
55 var ans = 0
6-
6+
77 for i in 0 ..< cnt {
88 ans += sortedCards [ n - i - 1 ]
99 }
10-
10+
1111 if ans % 2 == 0 {
1212 return ans
1313 }
14-
14+
1515 var smallestOddInside = Int . max
1616 var smallestEvenInside = Int . max
1717 var largestOddOutside = Int . min
1818 var largestEvenOutside = Int . min
19-
19+
2020 for i in ( n - cnt) ..< n {
2121 if sortedCards [ i] % 2 == 1 {
2222 smallestOddInside = min ( smallestOddInside, sortedCards [ i] )
2323 } else {
2424 smallestEvenInside = min ( smallestEvenInside, sortedCards [ i] )
2525 }
2626 }
27-
27+
2828 for i in 0 ..< ( n - cnt) {
2929 if sortedCards [ i] % 2 == 1 {
3030 largestOddOutside = max ( largestOddOutside, sortedCards [ i] )
3131 } else {
3232 largestEvenOutside = max ( largestEvenOutside, sortedCards [ i] )
3333 }
3434 }
35-
35+
3636 var maxScore = - 1
3737 if smallestOddInside != Int . max && largestEvenOutside != Int . min {
3838 maxScore = max ( maxScore, ans - smallestOddInside + largestEvenOutside)
3939 }
4040 if smallestEvenInside != Int . max && largestOddOutside != Int . min {
4141 maxScore = max ( maxScore, ans - smallestEvenInside + largestOddOutside)
4242 }
43-
43+
4444 return maxScore >= 0 ? maxScore : 0
4545 }
46- }
46+ }
You can’t perform that action at this time.
0 commit comments