From 9557fa8374fca37b7472309e0a3d8e0334198ff0 Mon Sep 17 00:00:00 2001 From: cezarbbb <105843128+cezarbbb@users.noreply.github.com> Date: Mon, 1 Aug 2022 15:20:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200406.=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E8=BA=AB=E9=AB=98=E9=87=8D=E5=BB=BA=E9=98=9F=E5=88=97=20Rust?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 0406.根据身高重建队列 Rust版本 --- problems/0406.根据身高重建队列.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/problems/0406.根据身高重建队列.md b/problems/0406.根据身高重建队列.md index 827b7481..75e0c40c 100644 --- a/problems/0406.根据身高重建队列.md +++ b/problems/0406.根据身高重建队列.md @@ -290,6 +290,26 @@ var reconstructQueue = function(people) { }; ``` +### Rust + +```Rust +impl Solution { + pub fn reconstruct_queue(people: Vec>) -> Vec> { + let mut people = people; + people.sort_by(|a, b| { + if a[0] == b[0] { return a[1].cmp(&b[1]); } + b[0].cmp(&a[0]) + }); + let mut que: Vec> = Vec::new(); + que.push(people[0].clone()); + for i in 1..people.len() { + let position = people[i][1]; + que.insert(position as usize, people[i].clone()); + } + que + } +} +``` ### C ```c