Member-only story
LeetCode Problem 206 — Reversed Linked List Solution
A walk through on how to reverse a linked list and solve the LeetCode problem #206.
An approach to solving LeetCode questions
If you’re new to LeetCode I wrote a guideline towards my approach to solving coding interview questions which you can find here : https://medium.com/@kristian.roopnarine/a-starting-approach-to-solving-coding-interview-questions-633dc03cbb0c .
In addition if you’re new to linked lists I have a general overview of this data structure here : https://levelup.gitconnected.com/data-structures-linked-lists-a3cfb0b728ac .
Question 206
This question is fairly straightforward, given a linked list input, return an output where it is reversed. In my opinion this question is deceptively easy. The difficult part is that this question requires the use of multiple pointers, we’ll need to keep track of the head
, next_node
and current_node
while iterating over the linked list.
Pseudo Code:
- Check if the head exists, or if there is at least two nodes. (Can’t reverse a linked list with 1 node)