WB Lee WB Lee - 1 year ago 73
Java Question

ListNode head.next.next = new ListNode(0); what is this error?

I just want to build a linked list, I do not know the reason of this problem. Could someone help me? Perhaps this is easy, but I cannot figure it out.

enter image description here

how to solve this problem?

Answer Source

Try this

ListNode head = new ListNode(0)

head.next = new ListNode(1)

head.next.next = new ListNode(2)

Do not put ListNode in front of head.next its already defined.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download