From b0c959e3a1e4c6e5d3182238058e5873bdea28eb Mon Sep 17 00:00:00 2001 From: ShashankZobb Date: Sun, 28 May 2023 19:57:02 +0530 Subject: [PATCH 1/2] fixed small issue --- cpp/0021-merge-two-sorted-lists.cpp | 14 +++----------- python/0128-longest-consecutive-sequence.py | 4 ++-- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/cpp/0021-merge-two-sorted-lists.cpp b/cpp/0021-merge-two-sorted-lists.cpp index febb22345..cae89422e 100644 --- a/cpp/0021-merge-two-sorted-lists.cpp +++ b/cpp/0021-merge-two-sorted-lists.cpp @@ -31,16 +31,8 @@ class Solution { return list1; } - ListNode* head = NULL; - if (list1->val <= list2->val) { - head = list1; - list1 = list1->next; - } else { - head = list2; - list2 = list2->next; - } - ListNode* curr = head; - + ListNode* dummy = new ListNode(); + ListNode *curr = dummy; while (list1 != NULL && list2 != NULL) { if (list1->val <= list2->val) { curr->next = list1; @@ -58,6 +50,6 @@ class Solution { curr->next = list1; } - return head; + return dummy->next; } }; diff --git a/python/0128-longest-consecutive-sequence.py b/python/0128-longest-consecutive-sequence.py index 4a2168ba4..f7e3d2bd6 100644 --- a/python/0128-longest-consecutive-sequence.py +++ b/python/0128-longest-consecutive-sequence.py @@ -1,9 +1,9 @@ class Solution: - def longestConsecutive(self, nums: List[int]) -> int: + def longestConsecutive(self, nums: list[int]) -> int: numSet = set(nums) longest = 0 - for n in nums: + for n in numSet: # check if its the start of a sequence if (n - 1) not in numSet: length = 1 From 5a7c47acc7089db058e96ce6ba12382673b2aacf Mon Sep 17 00:00:00 2001 From: ShashankZobb Date: Sun, 28 May 2023 20:00:12 +0530 Subject: [PATCH 2/2] fixed small issue --- python/0128-longest-consecutive-sequence.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/0128-longest-consecutive-sequence.py b/python/0128-longest-consecutive-sequence.py index f7e3d2bd6..11c63a8e8 100644 --- a/python/0128-longest-consecutive-sequence.py +++ b/python/0128-longest-consecutive-sequence.py @@ -1,5 +1,5 @@ class Solution: - def longestConsecutive(self, nums: list[int]) -> int: + def longestConsecutive(self, nums: List[int]) -> int: numSet = set(nums) longest = 0