From 309b49cf47699554a928354e2621575ec524db2f Mon Sep 17 00:00:00 2001 From: fw_qaq <82551626+Jack-Zhang-1314@users.noreply.github.com> Date: Mon, 31 Oct 2022 10:59:59 +0800 Subject: [PATCH] =?UTF-8?q?update=201047.=E5=88=A0=E9=99=A4=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E4=B8=AD=E7=9A=84=E6=89=80=E6=9C=89=E7=9B=B8?= =?UTF-8?q?=E9=82=BB=E9=87=8D=E5=A4=8D=E9=A1=B9.md=20about=20rust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...除字符串中的所有相邻重复项.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/problems/1047.删除字符串中的所有相邻重复项.md b/problems/1047.删除字符串中的所有相邻重复项.md index 849b5e79..ad729298 100644 --- a/problems/1047.删除字符串中的所有相邻重复项.md +++ b/problems/1047.删除字符串中的所有相邻重复项.md @@ -447,6 +447,25 @@ object Solution { } ``` +rust: + +```rust +impl Solution { + pub fn remove_duplicates(s: String) -> String { + let mut stack = vec![]; + let mut chars: Vec = s.chars().collect(); + while let Some(c) = chars.pop() { + if stack.is_empty() || stack[stack.len() - 1] != c { + stack.push(c); + } else { + stack.pop(); + } + } + stack.into_iter().rev().collect() + } +} +``` +