Skip to content

Instantly share code, notes, and snippets.

@yesidays
Last active April 10, 2020 16:23
Show Gist options
  • Save yesidays/2cf69197918ec74686f01d9cef23764c to your computer and use it in GitHub Desktop.
Save yesidays/2cf69197918ec74686f01d9cef23764c to your computer and use it in GitHub Desktop.
Backspace String Compare
class Solution(object):
def backspaceCompare(self, S, T):
"""
:type S: str
:type T: str
:rtype: bool
"""
def deleteBackspace(word):
temporal = []
for w in word:
if w != '#':
temporal.append(w)
elif temporal:
temporal.pop()
return ''.join(temporal)
return deleteBackspace(S) == deleteBackspace(T)
@munguial
Copy link

I like the simplicity of the deleteBackspace method. Well done.

@munguial
Copy link

It is just a matter of look but I would replace lines 18 to 24 to be something like:

return deleteBackspace(S) == deleteBackspace(T)

@yesidays
Copy link
Author

yesidays commented Apr 10, 2020

def deleteBackspace(word):
temporal = []
for w in word:
if w != '#':
temporal.append(w)
elif temporal:
temporal.pop()
return ''.join(temporal)

    return deleteBackspace(S) == deleteBackspace(T)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment