FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

week1 by liusuisui · Pull Request #853 · algorithm001/algorithm · GitHub

Open

week1 #853

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
22 changes: 22 additions & 0 deletions Week_01/id_56/LeetCode_21_056.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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;
}
};

Back | FazBrowse Home | New Git URL