Skip to content

Commit

Permalink
✨ Add solution for reverse singly linked list
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigmanificient committed Jun 26, 2023
1 parent 4405190 commit 8eeb528
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/python/katas/py6kyu/reverse_singly_linked_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Kata url: https://www.codewars.com/kata/57262ca48565846f33001365."""


def reverse_list(node):
nodes = []
first_node = node

while node is not None:
nodes.append(node)
node = node.next

cut = (len(nodes) // 2)
rev = nodes[::-1][:cut]

for node_front, node_back in zip(nodes, rev):
node_back.value, node_front.value = node_front.value, node_back.value
return first_node

0 comments on commit 8eeb528

Please sign in to comment.