![JAR search and dependency download from the Maven repository](/logo.png)
g0501_0600.s0561_array_partition_i.Solution.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
package g0501_0600.s0561_array_partition_i
// #Easy #Array #Sorting #Greedy #Counting_Sort
// #2023_01_21_Time_337_ms_(90.48%)_Space_41.1_MB_(97.62%)
class Solution {
fun arrayPairSum(nums: IntArray): Int {
nums.sort()
var sum = 0
var i = 0
while (i < nums.size - 1) {
sum += Math.min(nums[i], nums[i + 1])
i = i + 2
}
return sum
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy