repl.it
@rpat/

mergeLinkedList

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class listNode:
	def __init__(self,val):
		self.val = val
		self.next = None
def test(l1,l2):
	l3 = listNode(-1)
	root = l3
	while(l1 != None and l2!=None):
		if l1.val< l2.val:
			temp = listNode(l1.val)
			l3.next = temp
			l3 = l3.next
			l1=l1.next
		else:
			temp = listNode(l2.val)
			l3.next = temp
			l3=l3.next
			l2=l2.next
	if l1 == None:
		l3.next = l2
	else:
		l3.next = l1
	return root.next

Fetching token
?