My LeetCode grinding. Trying to do a problem a day.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223
  1. # There is a better way to do this, try think a little more.
  2. # Perhaps compare a char at a time? Need to be able to extend until the end of the string though.
  3. class Solution:
  4. def backspaceCompare(self, S: str, T: str) -> bool:
  5. resS = ""
  6. for c in S:
  7. if c != '#':
  8. resS += c
  9. elif len(resS) > 0:
  10. resS = resS[0:len(resS) - 1]
  11. resT = ""
  12. for c in T:
  13. if c != '#':
  14. resT += c
  15. elif len(resT) > 0:
  16. resT = resT[0:len(resT) - 1]
  17. return resS == resT
  18. s = Solution()
  19. print("Expected: True")
  20. print("Got:", s.backspaceCompare("xywrrmp", "xywrrmu#p"))