mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
添加 0406.根据身高重建队列.md Scala版本
This commit is contained in:
@ -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
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
-----------------------
|
||||
|
Reference in New Issue
Block a user