Skip to main content
Code Review

Return to Question

Commonmark migration
Source Link

Original Question.

So I rewrote the code for the problem described in the original question, but someone had already answered that question, and my rewrite would have invalidated their answer, so I just posted a new question.
##Updated Solution

Updated Solution

def sorted_insert(head, data):
 tmp = Node(None)
 tmp.next = head
 node = Node(data)
 while tmp.next:
 if tmp.next.data > data:
 break
 tmp = tmp.next
 node.next = tmp.next
 tmp.next = node
 return head if tmp.data else node

Original Question.

So I rewrote the code for the problem described in the original question, but someone had already answered that question, and my rewrite would have invalidated their answer, so I just posted a new question.
##Updated Solution

def sorted_insert(head, data):
 tmp = Node(None)
 tmp.next = head
 node = Node(data)
 while tmp.next:
 if tmp.next.data > data:
 break
 tmp = tmp.next
 node.next = tmp.next
 tmp.next = node
 return head if tmp.data else node

Original Question.

So I rewrote the code for the problem described in the original question, but someone had already answered that question, and my rewrite would have invalidated their answer, so I just posted a new question.

Updated Solution

def sorted_insert(head, data):
 tmp = Node(None)
 tmp.next = head
 node = Node(data)
 while tmp.next:
 if tmp.next.data > data:
 break
 tmp = tmp.next
 node.next = tmp.next
 tmp.next = node
 return head if tmp.data else node
Source Link
Tobi Alafin
  • 1.8k
  • 1
  • 15
  • 31

(Codewars) Linked Lists-Sorted Insert (2)

Original Question.

So I rewrote the code for the problem described in the original question, but someone had already answered that question, and my rewrite would have invalidated their answer, so I just posted a new question.
##Updated Solution

def sorted_insert(head, data):
 tmp = Node(None)
 tmp.next = head
 node = Node(data)
 while tmp.next:
 if tmp.next.data > data:
 break
 tmp = tmp.next
 node.next = tmp.next
 tmp.next = node
 return head if tmp.data else node
lang-py

AltStyle によって変換されたページ (->オリジナル) /