From edbff2f4f4746b09afa2d6dd8981f000d0bc75ae Mon Sep 17 00:00:00 2001 From: SevenMonths Date: Fri, 27 May 2022 15:04:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0(1047.=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E4=B8=AD=E7=9A=84=E6=89=80=E6=9C=89?= =?UTF-8?q?=E7=9B=B8=E9=82=BB=E9=87=8D=E5=A4=8D=E9=A1=B9.md)=EF=BC=9Aphp?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...除字符串中的所有相邻重复项.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/problems/1047.删除字符串中的所有相邻重复项.md b/problems/1047.删除字符串中的所有相邻重复项.md index 638c8f4e..65428394 100644 --- a/problems/1047.删除字符串中的所有相邻重复项.md +++ b/problems/1047.删除字符串中的所有相邻重复项.md @@ -375,5 +375,30 @@ func removeDuplicates(_ s: String) -> String { } ``` +PHP: +```php +class Solution { + function removeDuplicates($s) { + $stack = new SplStack(); + for($i=0;$iisEmpty() || $s[$i] != $stack->top()){ + $stack->push($s[$i]); + }else{ + $stack->pop(); + } + } + + $result = ""; + while(!$stack->isEmpty()){ + $result.= $stack->top(); + $stack->pop(); + } + + // 此时字符串需要反转一下 + return strrev($result); + } +} +``` + -----------------------