All problems

Backspace String Compare

Easy · two pointers

Two people each type a line of text into an empty text box. The strings s and t record every key they pressed, in order. A lowercase letter types that letter at the end of the text. The character # is the backspace key: it deletes the last letter typed so far, and does nothing if the text is empty.

Return true if the two people end up with exactly the same text, and false otherwise. Two empty texts are the same.

Examples

Example 1

Input: s = "ab#c", t = "ad#c"

Output: true

Both end up as "ac": the "b" in the first and the "d" in the second are deleted.

Example 2

Input: s = "a##b", t = "#b"

Output: true

In the first, the first # deletes "a" and the second # has nothing to delete, leaving "b". The second also ends as "b".

Example 3

Input: s = "abc#", t = "abd"

Output: false

The first ends as "ab" and the second as "abd".

Constraints