Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lined list merge two sorting list algo #428

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<h1>✨Happy Hacktoberfest 2023✨</h1>
<p>Hacktoberfest is a yearly event which encourages not only programmers and coders but also non-technical background to contribute in open source and start their journey with open source.</p>
<h1>Star Repo is Mandatory for Hactober Accepting!</h1>
Expand Down Expand Up @@ -52,4 +53,6 @@
| Ankita Sinha Ray |<a href="https://github.com/ankitasray">ankitasray</a>|
| Aditya Pandey |<a href="https://github.com/Aditya7pandey">Aditya7pandey</a>|
| Yash Bandal |<a href="https://github.com/Yash-Bandal">Yash Bandal</a>|
| Harshit Jaiswal |<a href="https://github.com/harshu84190">Harshit Jaiswal</a>|
| Harshit Jaiswal |<a href="https://github.com/harshu84190">Harshit Jaiswal</a>|
| Yashal Ali |<a href="(https://github.com/yashal-ali)">Yashal Ali </a>|

31 changes: 31 additions & 0 deletions Python/mergeTwoSortedList.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Merge Two Sorted Lists
# You are given the heads of two sorted linked lists list1 and list2.
# Merge the two lists in a one sorted list. The list should be made by splicing together the nodes of the first two lists.
# Return the head of the merged linked list.

# Input: list1 = [1,2,4], list2 = [1,3,4]
# Output: [1,1,2,3,4,4]

class ListNode:
def __init__(self, val=0, next=None):
self.val = val
self.next = next

class Solution:
def mergeTwoLists(self, list1, list2):
curr = dummy = ListNode()
while list1 and list2:
if list1.val < list2.val:
curr.next = list1
list1 = list1.next
else:
curr.next = list2
list2 = list2.next
curr = curr.next

if list1:
curr.next = list1
else:
curr.next = list2

return dummy.next