Skip to content

Practice Backspace String Compare

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#844
LeetCode Problem

Backspace String Compare

Problem Statement

Compare the text produced by typing s and t into separate empty editors. Each # deletes the immediately preceding character if there is one; deleting from an empty editor leaves it empty. Return whether the final texts match. Follow-up: use O(n) time and O(1) extra space.

Source: Backspace String Compare on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "ab#c", t = "ad#c"
Output
true

# Example 2

Input
s = "ab##", t = "c#d#"
Output
true

# Example 3

Input
s = "a#c", t = "b"
Output
false

Constraints

1 <= s.length, t.length <= 200
s and t only contain lowercase letters and '#' characters.

Related LeetCode Problems

Practice more problems similar to Backspace String Compare.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.