Backspace String Compare Solutions in C++Number 844Difficulty EasyAcceptance 46.4%Link LeetCodeOther languages GoSolutionsC++ solution by haoel/leetcode// Source : https://leetcode.com/problems/backspace-string-compare/description/// Author : Hao Chen// Date : 2018-06-29 class Solution {private: void removeBackspaces(string &s) { int i = 0; for(int i=0; i<s.size(); i++) { if (s[i] == '#') { int backSteps = i>0 ? 2 : 1; s.erase(i-backSteps + 1, backSteps); i -= backSteps; } } } public: bool backspaceCompare(string S, string T) { removeBackspaces(S); removeBackspaces(T); return S == T; }};// Source : https://leetcode.com/problems/backspace-string-compare/description/ // Author : Hao Chen // Date : 2018-06-29 class Solution { private: void removeBackspaces(string &s) { int i = 0; for(int i=0; i<s.size(); i++) { if (s[i] == '#') { int backSteps = i>0 ? 2 : 1; s.erase(i-backSteps + 1, backSteps); i -= backSteps; } } } public: bool backspaceCompare(string S, string T) { removeBackspaces(S); removeBackspaces(T); return S == T; } };