가장 수를 평평하게 만드는법->제일 작은수와 제일큰수를 더한다
풀이:정렬쳐서 맨앞과 맨뒤를 더하고 그걸 집합에 추가,그중 max쳐서 리턴
class Solution {
fun minPairSum(nums: IntArray): Int {
val numList= nums.toList().sorted()
val resSet = mutableSetOf<Int>()
for (i in numList.indices){
resSet.add(numList.asReversed()[i]+numList[i])
}
return resSet.max()
}
}
'알고리즘' 카테고리의 다른 글
릿코드 1887. Reduction Operations to Make the Array Elements Equal 코틀린 (1) | 2023.11.20 |
---|---|
릿코드 1838. Frequency of the Most Frequent Element 코틀린 (0) | 2023.11.19 |
릿코드 1980. Find Unique Binary String 코틀린 (0) | 2023.11.17 |
릿코드 1846. Maximum Element After Decreasing and Rearranging 코틀린 (1) | 2023.11.16 |
릿코드 1930. Unique Length-3 Palindromic Subsequences 코틀린 (1) | 2023.11.15 |