-
[LeetCode] 1047. Remove All Adjacent Duplicates In StringLeetCode 2021. 11. 1. 16:38728x90
https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/
Remove All Adjacent Duplicates In String - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
Remove All Adjacent Duplicates In String - Easy

문자열에서 중복해있는 두개의 문자열이 없도록 하는 문제다.
스택을 이용해 쌓아주고, 겹치면 제거해주면 된다.
전체 풀이 코드
class Solution { public: string removeDuplicates(string s) { stack<char> st; string ret; for (int i=0; i<s.size(); i++) { if (!st.empty() && st.top()==s[i]) st.pop(); else st.push(s[i]); } while(!st.empty()) ret+=st.top(), st.pop(); reverse(ret.begin(), ret.end()); return ret; } };'LeetCode' 카테고리의 다른 글
[LeetCode] 129. Sum Root to Leaf Numbers (0) 2021.11.03 [LeetCode] 1481. Least Number of Unique Integers after K Removals (0) 2021.11.01 [LeetCode] 130. Surrounded Regions (0) 2021.11.01 [LeetCode] 994. Rotting Oranges (0) 2021.10.29 [LeetCode] 342. Power of Four (0) 2021.10.29