From 411ddc318d9dbaccd39872bd69dd71a7846ccba2 Mon Sep 17 00:00:00 2001 From: 3119005212 <1136153224@qq.com> Date: Wed, 5 May 2021 16:37:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=88=E5=92=8C=E9=98=9F=E5=88=97=E4=B8=93?= =?UTF-8?q?=E9=A2=98=E6=9B=B4=E6=96=B0cpp=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../栈和队列/225.用队列实现栈.md | 31 +++++++++++++++++++ .../leetcode1047 删除字符串中的所有相邻重复项.md | 26 ++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/animation-simulation/栈和队列/225.用队列实现栈.md b/animation-simulation/栈和队列/225.用队列实现栈.md index ccaa942..db69b8b 100644 --- a/animation-simulation/栈和队列/225.用队列实现栈.md +++ b/animation-simulation/栈和队列/225.用队列实现栈.md @@ -18,6 +18,8 @@ 下面我们来看一下题目代码,也是很容易理解。 +#### 题目代码 + Java Code: ```java class MyStack { @@ -87,3 +89,32 @@ MyStack.prototype.empty = function() { }; ``` +C++ Code: + +```cpp +class MyStack { + queue q; +public: + void push(int x) { + q.push(x); + for(int i = 1;i < q.size();i++){ + int val = q.front(); + q.push(val); + q.pop(); + } + } + + int pop() { + int val = q.front(); + q.pop(); + return val; + } + int top() { + return q.front(); + } + bool empty() { + return q.empty(); + } +}; +``` + diff --git a/animation-simulation/栈和队列/leetcode1047 删除字符串中的所有相邻重复项.md b/animation-simulation/栈和队列/leetcode1047 删除字符串中的所有相邻重复项.md index 2344bb8..c5184fa 100644 --- a/animation-simulation/栈和队列/leetcode1047 删除字符串中的所有相邻重复项.md +++ b/animation-simulation/栈和队列/leetcode1047 删除字符串中的所有相邻重复项.md @@ -29,9 +29,11 @@ +**题目代码** +Java Code: ```java class Solution { @@ -67,3 +69,27 @@ class Solution { ``` 当然这个题目也可以用 set 来做,大家可以随意发挥 + +C++ Code: + +```cpp +class Solution { +public: +string removeDuplicates(string S) { + string str; + if (S.empty() || S.size() == 1) { + return S; + } + for (int i = 0; i