[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"searchBlogPosts":3,"$f89s1YxztdjAlECdXifw0XEdSwxYBZ0xcH3kTN7YVe8U":7},[4],{"_path":5,"title":6},"\u002Fblog\u002F2023\u002F09\u002F17\u002Fspring-boot-postgresql","Spring Boot with PostgreSQL & pgAdmin in Docker",{"title":8,"category":9,"problemHtml":10,"solutions":11,"repoUrl":20},"Merge Two Sorted Linked Lists","Data Structures & Algorithms","",[12,16],{"lang":13,"label":14,"html":15},"java","Java","\u003Cpre>\u003Ccode class=\"language-java\">\u002F**\n * Definition for singly-linked list.\n * public class ListNode {\n *     int val;\n *     ListNode next;\n *     ListNode() {}\n *     ListNode(int val) { this.val = val; }\n *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n *\u002F\n\nclass Solution {\n    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {\n        ListNode dummy = new ListNode(0);\n        ListNode node = dummy;\n\n        while(list1 != null &amp;&amp; list2 != null) {\n            if(list1.val &lt; list2.val){\n                node.next = list1;\n                list1 = list1.next;\n            } else {\n                node.next = list2;\n                list2 = list2.next;\n            }\n\n            node = node = node.next;\n        }\n\n        if(list1 != null) node.next = list1;\n        else node.next = list2;\n\n        return dummy.next;\n    }\n}\u003C\u002Fcode>\u003C\u002Fpre>",{"lang":17,"label":18,"html":19},"python","Python","\u003Cpre>\u003Ccode class=\"language-python\"># Definition for singly-linked list.\n# class ListNode:\n#     def __init__(self, val=0, next=None):\n#         self.val = val\n#         self.next = next\n\nclass Solution:\n    def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -&gt; Optional[ListNode]:\n        if list1 is None:\n            return list2\n        if list2 is None:\n            return list1\n        \n        if list1.val &lt;= list2.val:\n            list1.next = self.mergeTwoLists(list1.next, list2)\n\n            return list1\n        else:\n            list2.next = self.mergeTwoLists(list1, list2.next)\n\n            return list2\u003C\u002Fcode>\u003C\u002Fpre>","https:\u002F\u002Fgithub.com\u002Fvishwarajsali\u002FInterviewPrep\u002Ftree\u002Fmain\u002FData%20Structures%20%26%20Algorithms%2Fmerge-two-sorted-linked-lists"]