题解 | #无环单链表插值#
无环单链表插值
http://www.nowcoder.com/practice/3ccf07c4d7374cc685be4a3883708540
import java.util.*;
public class Solution {
public ListNode insert (int[] A, int val) {
ListNode head = new ListNode(0);
ListNode temp = head;
boolean flag = true;
for (int i=0;i<A.length;i++){
if (A[i]>val&&flag==true){
ListNode now = new ListNode(val);
temp.next = now;
temp = temp.next;
flag = false;
}
ListNode now = new ListNode(A[i]);
temp.next = now;
temp = temp.next;
}
if (flag==true){
ListNode now = new ListNode(val);
temp.next = now;
temp = temp.next;
}
return head.next;
}
}