diff --git a/problems/0406.根据身高重建队列.md b/problems/0406.根据身高重建队列.md index 641086a9..516df7d7 100644 --- a/problems/0406.根据身高重建队列.md +++ b/problems/0406.根据身高重建队列.md @@ -354,8 +354,27 @@ function reconstructQueue(people: number[][]): number[][] { }; ``` +### Scala +```scala +object Solution { + import scala.collection.mutable + def reconstructQueue(people: Array[Array[Int]]): Array[Array[Int]] = { + val person = people.sortWith((a, b) => { + if (a(0) == b(0)) a(1) < b(1) + else a(0) > b(0) + }) + var que = mutable.ArrayBuffer[Array[Int]]() + + for (per <- person) { + que.insert(per(1), per) + } + + que.toArray + } +} +``` -----------------------