844. Backspace String Compare
https://leetcode.com/problems/backspace-string-compare/
public class Solution {
public bool BackspaceCompare(string s, string t) {
return GetString(s) == GetString(t);
}
public string GetString(string str) {
int count = 0;
var sb = new StringBuilder();
for(int i = str.Length - 1; i >= 0; i--){
if(str[i] == '#'){
count++;
continue;
}
else if(count > 0)
count--;
else{
sb.Append(str[i]);
}
}
return sb.ToString();
}
}Stack
Last updated
Was this helpful?