标签:ext node new solution int return pre bsp class
1 class Solution { 2 public ListNode partition(ListNode head, int x) { 3 ListNode newHead = null; 4 ListNode node2 = null; 5 ListNode node1 = head; 6 while(node1 != null) { 7 if(node1.val < x) { 8 if(newHead == null) { 9 newHead = new ListNode(node1.val); 10 node2 = newHead; 11 }else { 12 node2.next = new ListNode(node1.val); 13 node2 = node2.next; 14 } 15 16 } 17 node1 = node1.next; 18 } 19 20 node1 = head; 21 while(node1 != null) { 22 if(node1.val >= x) { 23 if(newHead == null) { 24 newHead = new ListNode(node1.val); 25 node2 = newHead; 26 }else { 27 node2.next = new ListNode(node1.val); 28 node2 = node2.next; 29 } 30 31 } 32 node1 = node1.next; 33 } 34 return newHead; 35 36 } 37 }
标签:ext node new solution int return pre bsp class
原文地址:https://www.cnblogs.com/goPanama/p/9655293.html