标签:new 自己 write img logs put pre open alt
2017-9-27
1 public class Solution { 2 /* 3 * @param node: a list node in the list 4 * @param x: An integer 5 * @return: the inserted new list node 6 */ 7 public ListNode insert(ListNode node, int x) { 8 // write your code here 9 if (node == null) { 10 ListNode node1 = new ListNode(x); 11 node1.next = node1; 12 return node1; 13 } 14 ListNode cur = node; 15 ListNode temp = node.next; 16 if (temp.val < x) { 17 cur = cur.next; 18 temp = temp.next; 19 } 20 ListNode newNode = new ListNode(x); 21 cur.next = newNode; 22 newNode.next = temp; 23 return temp; 24 } 25 }
30->50->2->2->3->5->7->9->11->20 2
50->2->2->2->3->5->7->9->11->20->30
我的错哪里了30->2->50->2->2->3->5->7->9->11->20
想简单了。
标签:new 自己 write img logs put pre open alt
原文地址:http://www.cnblogs.com/yunyouhua/p/7603412.html