瀏覽代碼

April Day 9 Done

master
Lachlan Jacob 5 年之前
父節點
當前提交
123511f124
共有 3 個文件被更改,包括 62 次插入0 次删除
  1. 23
    0
      problems/844/main.py
  2. 36
    0
      problems/844/problem.txt
  3. 3
    0
      problems/844/run.sh

+ 23
- 0
problems/844/main.py 查看文件

@@ -0,0 +1,23 @@
# There is a better way to do this, try think a little more.
# Perhaps compare a char at a time? Need to be able to extend until the end of the string though.

class Solution:
def backspaceCompare(self, S: str, T: str) -> bool:
resS = ""
for c in S:
if c != '#':
resS += c
elif len(resS) > 0:
resS = resS[0:len(resS) - 1]
resT = ""
for c in T:
if c != '#':
resT += c
elif len(resT) > 0:
resT = resT[0:len(resT) - 1]
return resS == resT

s = Solution()
print("Expected: True")
print("Got:", s.backspaceCompare("xywrrmp", "xywrrmu#p"))

+ 36
- 0
problems/844/problem.txt 查看文件

@@ -0,0 +1,36 @@
Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.

Example 1:

Input: S = "ab#c", T = "ad#c"
Output: true
Explanation: Both S and T become "ac".

Example 2:

Input: S = "ab##", T = "c#d#"
Output: true
Explanation: Both S and T become "".

Example 3:

Input: S = "a##c", T = "#a#c"
Output: true
Explanation: Both S and T become "c".

Example 4:

Input: S = "a#c", T = "b"
Output: false
Explanation: S becomes "c" while T becomes "b".

Note:

1 <= S.length <= 200
1 <= T.length <= 200
S and T only contain lowercase letters and '#' characters.

Follow up:

Can you solve it in O(N) time and O(1) space?


+ 3
- 0
problems/844/run.sh 查看文件

@@ -0,0 +1,3 @@
#!/bin/bash

python3 main.py

Loading…
取消
儲存