Skip to content

week1 #853

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

week1 #853

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
22 changes: 22 additions & 0 deletions Week_01/id_56/LeetCode_21_056.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class Solution {
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
if(l1 == null && l2 == null)
return null;
if(l1 == null)
return l2;
if(l2 == null)
return l1;
ListNode head = null;
if(l1.val > l2.val)
{
head = l2;
head.next = mergeTwoLists(l1, l2.next);
}
else
{
head = l1;
head.next = mergeTwoLists(l1.next, l2);
}
return head;
}
}
17 changes: 17 additions & 0 deletions Week_01/id_56/LeetCode_83_056.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
if ((head == nullptr) || (head->next == nullptr)) return head;
ListNode* node = head;
ListNode* nextNode = node->next;
while (nextNode != nullptr) {
if (nextNode->val == node->val) {
node->next = nextNode->next;
nextNode->next = nullptr;
} else node = nextNode;
nextNode = node->next;
}

return head;
}
};