Member-only story

LeetCode Problem 206 — Reversed Linked List Solution

Kristian Roopnarine
2 min readJul 8, 2020

A walk through on how to reverse a linked list and solve the LeetCode problem #206.

Source (leetcode.com)

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

Description of the question

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:

  1. Check if the head exists, or if there is at least two nodes. (Can’t reverse a linked list with 1 node)

--

--

Kristian Roopnarine
Kristian Roopnarine

Written by Kristian Roopnarine

Full Stack Engineer sharing tips and tricks for anyone learning to program. Connect with me on LinkedIn : https://www.linkedin.com/in/kristianroopnarine/

No responses yet