public static ListNode buildLinks(int[] arr) {
ListNode head = null;
for (int e : arr) {
head = buildLink(head, e);
}
return head;
}
public static ListNode buildLink(ListNode head, int v) {
if (head == null) {
head = new ListNode(v);
return head;
}
ListNode tem = head;
while (tem != null) {
if (tem.next == null)
break;
tem = tem.next;
}
tem.next = new ListNode(v);
return head;
}