정렬치고 가장큰값2개 가장작은값2개 곱해서 빼기
정답
class Solution {
fun maxProductDifference(nums: IntArray): Int {
val sortedList = nums.sorted()
val listSize = sortedList.size
return (sortedList[listSize-1]*sortedList[listSize-2])-(sortedList[0]*sortedList[1])
}
}
'알고리즘' 카테고리의 다른 글
릿코드 2706. Buy Two Chocolates 코틀린 (0) | 2023.12.20 |
---|---|
릿코드 661. Image Smoother 코틀린 (0) | 2023.12.19 |
릿코드 242. Valid Anagram 코틀린 (0) | 2023.12.16 |
릿코드 1436. Destination City 코틀린 (0) | 2023.12.15 |
릿코드 2482. Difference Between Ones and Zeros in Row and Column 코틀린 (0) | 2023.12.14 |