g0401_0500.s0406_queue_reconstruction_by_height.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 g0401_0500.s0406_queue_reconstruction_by_height
// #Medium #Array #Sorting #Greedy #Segment_Tree #Binary_Indexed_Tree
// #2022_12_03_Time_306_ms_(100.00%)_Space_44.9_MB_(84.62%)
class Solution {
fun reconstructQueue(people: Array): Array {
return people.sortedWith(compareBy({ -it[0] }, { it[1] }))
.fold(mutableListOf()) { output, p -> output.add(p[1], p); output }
.toTypedArray()
}
}