Use a prev
to record the previous node, and if the current node is duplicated by the next node, delete them. Otherwise move prev
forward.
Time complexity:
o
(
n
)
o(n)
o(n)
Space complexity:
o
(
1
)
o(1)
o(1)