알고리즘 문제풀이/LeetCode

LeetCode 844번 - Backspace String Compare

leetcode.com/problems/backspace-string-compare/

 

Backspace String Compare - 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

 

class Solution {
public:
    bool backspaceCompare(string S, string T) {
        int sizes = S.size();
        int sizet = T.size();
        
        while(S.find('#') != -1){
             if(S.find('#') == 0){
                 S.erase(S.find('#'), 1);
            }
            else{
            S.erase(S.find('#') -1, 2);
            }
        }
        
        while(T.find('#') != -1){
            if(T.find('#') == 0){
                 T.erase(T.find('#'), 1);
            }
            else{
            T.erase(T.find('#') -1, 2);
            }
        }
        
        if(S == T){
            return true;
        }
 
        return false;
    }
};