2021-09-13から1日間の記事一覧

1047. Remove All Adjacent Duplicates In String

stackで貯めていき、stackのtopと同じ文字がきたら、popする。 '''cpp class Solution { public: string removeDuplicates(string s) { stackst; for(char i:s) { if(st.size() == 0) { st.push(i); } else if(i == st.top()) { st.pop(); } else { st.push(…

796. Rotate String

substrで切り取って、一文字目を足せば良いのか https://leetcode.com/problems/rotate-string/discuss/947059/C%2B%2B-or-Simple-Solution-or-Faster-than-100 class Solution { public: bool rotateString(string s, string goal) { int len = goal.size()…