Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Python by marker ( 4 years ago )
# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
        

import numpy as np

# Generate a list of nodes with random values
nodelist=[]
for i in range(1,11):
    nodelist.append(ListNode(np.random.randint(1,11)))

# Link the nodes
for i in range(len(nodelist)-1):
    nodelist[i].next=nodelist[i+1]
    
# Name first node "head"
head=nodelist[0]

# Print the linked list
printnodelist=[]
for i in range(len(nodelist)):
    printnodelist.append(nodelist[i].val)
print(printnodelist)

 

Revise this Paste

Your Name: Code Language: