[leetcode] Backspace String Compare

jun·2021년 3월 26일
0
post-thumbnail

유의할점

분리된 투포인터 ?

투포인터로 풀어볼것

풀이

stack을 이용해서 풀었다. time : O(N) space : O(N)

투포인터를 이용, space를 O(N)으로 만들수있다. 시도해보자

코드

C++ : 내가 짠 코드


class Solution {
public:
    string makeString(string s){
        string res;
        for(char c : s){
            if(c=='#'){
                if(!res.empty()) res.pop_back();    
            }
            else
                res.push_back(c);
        }
        return res;
    }
    bool backspaceCompare(string S, string T) {
        S = makeString(S) ;
        T = makeString(T) ;
        return S==T;        
    }
};
profile
Computer Science / Algorithm / Project / TIL

0개의 댓글