Ejemplo n.º 1
0
        public static ListNode GetListNode(int[] intArray)
        {
            if (intArray.Length == 1)
            {
                return(new ListNode(intArray[0]));
            }
            var head  = new ListNode(intArray[0]);
            var nodes = new List <ListNode>();

            for (var i = 1; i < intArray.Length; i++)
            {
                var next = new ListNode(intArray[i]);
                nodes.Add(next);
            }

            for (var i = 0; i < nodes.Count - 1; i++)
            {
                nodes[i].next = nodes[i + 1];
            }

            head.next = nodes[0];

            return(head);
        }
Ejemplo n.º 2
0
 public ListNode(int val = 0, ListNode next = null)
 {
     this.val  = val;
     this.next = next;
 }