diff --git a/1047-Remove-All-Adjacent-Duplicates-In-String/cpp-1047/CMakeLists.txt b/1047-Remove-All-Adjacent-Duplicates-In-String/cpp-1047/CMakeLists.txt new file mode 100644 index 00000000..3c6ea462 --- /dev/null +++ b/1047-Remove-All-Adjacent-Duplicates-In-String/cpp-1047/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.14) +project(B) + +set(CMAKE_CXX_STANDARD 14) + +add_executable(B main.cpp) \ No newline at end of file diff --git a/1047-Remove-All-Adjacent-Duplicates-In-String/cpp-1047/main.cpp b/1047-Remove-All-Adjacent-Duplicates-In-String/cpp-1047/main.cpp new file mode 100644 index 00000000..1d8237ff --- /dev/null +++ b/1047-Remove-All-Adjacent-Duplicates-In-String/cpp-1047/main.cpp @@ -0,0 +1,31 @@ +/// Source : https://leetcode.com/problems/two-sum/description/ +/// Author : liuyubobobo +/// Time : 2019-05-18 + +#include + +using namespace std; + + +/// Using Stack +/// Time Complexity: O(|S|) +/// Space Complexity: O(1) +class Solution { +public: + string removeDuplicates(string S) { + + string res = ""; + for(char c: S) + if(!res.size() || res.back() != c) + res += c; + else + res.pop_back(); + return res; + } +}; + + +int main() { + + return 0; +} \ No newline at end of file diff --git a/readme.md b/readme.md index 84198be9..0d55a5f9 100644 --- a/readme.md +++ b/readme.md @@ -730,4 +730,5 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com) | 1044 | [Longest Duplicate Substring](https://leetcode.com/problems/longest-duplicate-substring/) | [无]
[缺:后缀数组] | [C++](1044-Longest-Duplicate-Substring/cpp-1044/) | | | | | | | | | | | 1046 | [Last Stone Weight](https://leetcode.com/problems/last-stone-weight/) | [无] | [C++](1046-Last-Stone-Weight/cpp-1046/) | | | +| 1047 | [Remove All Adjacent Duplicates In String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/) | [无] | [C++](1047-Remove-All-Adjacent-Duplicates-In-String/cpp-1047/) | | | | | | | | | | \ No newline at end of file