JAVA_LeetCode 86_Partition List 풀이 class Solution { public ListNode partition(ListNode head, int x) { // 특정값 기준으로 나눠 노드에 차례대로 붙인 다음 마지막에 두 노드를 붙여준다. ListNode dummy1 = new ListNode(0); // 앞쪽 더미노드 ListNode dummy2 = new ListNode(0); // 뒤쪽 더미노드 ListNode node1 = dummy1; // 앞쪽 노드 ListNode node2 = dummy2; // 뒤쪽 노드 while(head !
= null){ if(head.val < x){ // 앞쪽 노드 node1.next = head; node1 = node1.next; }else{ // 뒤쪽 노드 node2.next = head; node2 = node2.next; } head = head.next; } node2.next = null; // 뒤쪽 노드...
원문 링크 : JAVA_LeetCode 86_Partition List