mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2025-08-06 15:32:12 +00:00
栈和队列专题更新cpp代码
This commit is contained in:
@@ -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<S.size(); i++) {
|
||||
if(str.empty() || S[i] != str.back()) {
|
||||
str.push_back(S[i]);
|
||||
}
|
||||
else {
|
||||
str.pop_back();
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user