mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 02:53:31 +08:00
@ -222,7 +222,7 @@ class Solution:
|
||||
```
|
||||
|
||||
Go:
|
||||
```golang
|
||||
```go
|
||||
func reconstructQueue(people [][]int) [][]int {
|
||||
//先将身高从大到小排序,确定最大个子的相对位置
|
||||
sort.Slice(people,func(i,j int)bool{
|
||||
@ -241,7 +241,38 @@ func reconstructQueue(people [][]int) [][]int {
|
||||
return result
|
||||
}
|
||||
```
|
||||
```go
|
||||
//链表法
|
||||
func reconstructQueue(people [][]int) [][]int {
|
||||
sort.Slice(people,func (i,j int) bool {
|
||||
if people[i][0]==people[j][0]{
|
||||
return people[i][1]<people[j][1]//当身高相同时,将K按照从小到大排序
|
||||
}
|
||||
//先将身高从大到小排序,确定最大个子的相对位置
|
||||
return people[i][0]>people[j][0]
|
||||
})
|
||||
l:=list.New()//创建链表
|
||||
for i:=0;i<len(people);i++{
|
||||
position:=people[i][1]
|
||||
mark:=l.PushBack(people[i])//插入元素
|
||||
e:=l.Front()
|
||||
for position!=0{//获取相对位置
|
||||
position--
|
||||
e=e.Next()
|
||||
}
|
||||
l.MoveBefore(mark,e)//移动位置
|
||||
|
||||
}
|
||||
res:=[][]int{}
|
||||
for e:=l.Front();e!=nil;e=e.Next(){
|
||||
res=append(res,e.Value.([]int))
|
||||
}
|
||||
return res
|
||||
}
|
||||
```
|
||||
|
||||
Javascript:
|
||||
|
||||
```Javascript
|
||||
var reconstructQueue = function(people) {
|
||||
let queue = []
|
||||
|
Reference in New Issue
Block a user