We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给定 S 和 T 两个字符串,当它们分别被输入到空白的文本编辑器后,判断二者是否相等,并返回结果。 # 代表退格字符。
注意:如果对空文本输入退格字符,文本继续为空。
输入:S = "ab#c", T = "ad#c" 输出:true 解释:S 和 T 都会变成 “ac”。
输入:S = "ab##", T = "c#d#" 输出:true 解释:S 和 T 都会变成 “”。
输入:S = "a##c", T = "#a#c" 输出:true 解释:S 和 T 都会变成 “c”。 示例 4: 输入:S = "a#c", T = "b" 输出:false 解释:S 会变成 “c”,但 T 仍然是 “b”。
你可以用 O(N) 的时间复杂度和 O(1) 的空间复杂度解决该问题吗?
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/backspace-string-compare
The text was updated successfully, but these errors were encountered:
使用栈就很简单了,分别对两个字符串处理即可
func backspaceCompare(S string, T string) bool { return getEnd(S) == getEnd(T) } func getEnd(s string) string { var ret []byte for i := 0; i < len(s); i++ { if s[i] == '#' { if len(ret) == 0 { continue } ret = ret[0 : len(ret)-1] } else { ret = append(ret, s[i]) } } return string(ret) }
Sorry, something went wrong.
No branches or pull requests
给定 S 和 T 两个字符串,当它们分别被输入到空白的文本编辑器后,判断二者是否相等,并返回结果。 # 代表退格字符。
注意:如果对空文本输入退格字符,文本继续为空。
示例 1:
示例 2:
示例 3:
提示:
进阶:
你可以用 O(N) 的时间复杂度和 O(1) 的空间复杂度解决该问题吗?
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/backspace-string-compare
The text was updated successfully, but these errors were encountered: