use of com.fishercoder.common.classes.ListNode in project Leetcode by fishercoder1534.
the class _725Test method test2.
@Test
public void test2() {
root = LinkedListUtils.contructLinkedList(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
k = 3;
actual = solution1.splitListToParts(root, k);
for (ListNode head : actual) {
ListNode.printList(head);
}
}
use of com.fishercoder.common.classes.ListNode in project Leetcode by fishercoder1534.
the class _725Test method test4.
@Test
public void test4() {
root = LinkedListUtils.contructLinkedList(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
k = 3;
actual = solution2.splitListToParts(root, k);
for (ListNode head : actual) {
ListNode.printList(head);
}
}
use of com.fishercoder.common.classes.ListNode in project Leetcode by fishercoder1534.
the class _23 method mergeKLists.
public ListNode mergeKLists(ListNode[] lists) {
PriorityQueue<ListNode> heap = new PriorityQueue(new Comparator<ListNode>() {
@Override
public int compare(ListNode o1, ListNode o2) {
return o1.val - o2.val;
}
});
for (ListNode node : lists) {
if (node != null) {
heap.offer(node);
}
}
ListNode pre = new ListNode(-1);
ListNode temp = pre;
while (!heap.isEmpty()) {
ListNode curr = heap.poll();
temp.next = new ListNode(curr.val);
if (curr.next != null) {
heap.offer(curr.next);
}
temp = temp.next;
}
return pre.next;
}
use of com.fishercoder.common.classes.ListNode in project Leetcode by fishercoder1534.
the class _24 method swapPairs.
public ListNode swapPairs(ListNode head) {
if (head == null || head.next == null) {
return head;
}
ListNode second = head.next;
ListNode third = second.next;
second.next = head;
head.next = swapPairs(third);
return second;
}
use of com.fishercoder.common.classes.ListNode in project Leetcode by fishercoder1534.
the class _328 method oddEvenList.
public ListNode oddEvenList(ListNode head) {
if (head != null) {
ListNode odd = head;
ListNode even = head.next;
ListNode evenHead = even;
while (even != null && even.next != null) {
odd.next = odd.next.next;
even.next = even.next.next;
odd = odd.next;
even = even.next;
}
odd.next = evenHead;
}
return head;
}
Aggregations