From 086842d66e8bdbf639eda60d759b90fd1e60d72b Mon Sep 17 00:00:00 2001 From: RITIK PATIDAR <101919743+ritikpatel17@users.noreply.github.com> Date: Mon, 31 Oct 2022 22:49:29 +0530 Subject: [PATCH] Merge k Sorted Lists --- mergeKLists.java | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 mergeKLists.java diff --git a/mergeKLists.java b/mergeKLists.java new file mode 100644 index 0000000..251981e --- /dev/null +++ b/mergeKLists.java @@ -0,0 +1,43 @@ +/** + * Definition for singly-linked list. + * public class ListNode { + * int val; + * ListNode next; + * ListNode() {} + * ListNode(int val) { this.val = val; } + * ListNode(int val, ListNode next) { this.val = val; this.next = next; } + * } + */ +class Solution { + public ListNode mergeKLists(ListNode[] lists) { + + //ListNode a = new ListNode(); + if(lists.length==0){ + return null; + } + + for(int k=1; k