online_judge
, python3
給定兩個只包含字母和#
的字串,其中#
代表 backspace,問兩個字串在處理完 backspace 後一否一致。
從字串末尾開始掃描,即可把 backspace 轉化為 delete,這時候就變成遇到#
就無視下一個字元了。
然而#
可能會連續出現,所以需要記錄#
連續出現多少次,然後無視同樣多個字元。
Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.
Note that after backspacing an empty text, the text will continue empty.
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?
class Solution:
def backspaceCompare(self, S, T):
S += "a"
T += "a"
i = len(S) -1
j = len(T) -1
while i > -1 and j > -1:
if S[i] != T[j]:
return False
S_backspace = 1
while S_backspace > 0 and i > -1:
i -= 1
S_backspace -= 1
if S[i] == "#":
S_backspace += 2
T_backspace = 1
while T_backspace > 0 and j > -1:
j -= 1
T_backspace -= 1
if T[j] == "#":
T_backspace += 2
while i > -1 and S[i] == "#":
S_backspace = 1
while S_backspace > 0 and i > -1:
i -= 1
S_backspace -= 1
if S[i] == "#":
S_backspace += 2
while j > -1 and T[j] == "#":
T_backspace = 1
while T_backspace > 0 and j > -1:
j -= 1
T_backspace -= 1
if T[j] == "#":
T_backspace += 2
"""print(S[i])
print(T[j])"""
if i < 0 and j < 0:
return True
else:
return False
a = Solution()
print (a.backspaceCompare("ab#c","ad#c"))
print (a.backspaceCompare("ab##","c#d#"))
print (a.backspaceCompare("a##c","#a#c"))
print (a.backspaceCompare("a#c","b"))
print (a.backspaceCompare("bxj##tw","bxo#j##tw"))
tmux 的全稱是 Terminal Multiplexer,直譯過來就是終端(Terminal)多工器(Multiplexer),這個工具可以在單一 screen 之下 create, attach, detach 多個終端,熟悉之後十分好用。只是和 vim,vi 系列相同,所有操作皆能且只能使用鍵盤,不像 GNOME Terminal 一樣有直觀的 GUI 介面,算不上友善的學習曲線使人又愛又恨。關於 tmux 的基本概念和入門組合鍵,G. T. Wang 的文章提供了很不錯的繁體中文資料,本篇的重點在於如何配合 shell script 和 tmux 來快速建立一個順手的工作區。
Sep 18, 2024轉眼就在日本工作快半年了,想說就來整理一下求職當下的記錄吧。先說一下小弟我的狀況,原本其實是沒有來日本工作的計劃,打算就老老實實GG輪班救台灣的。只是剛好修個日文課,剛好老師介紹下參加了幾場面試,誤打誤撞的就拿到了還算可以的內定。瞄著日本的綠卡傻傻的就跑來了。所以說人生啊,緣分真的很重要。而計劃,永遠趕不上變化。
May 31, 2024Introduction
Jun 21, 2023Revision record version comment author v0.1.0 document built Marco Ma
Jan 20, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up