Skip to content

Commit 127c9c3

Browse files
authored
Merge pull request #2520 from ShashankZobb/main
Fixed small issue
2 parents 0ed3aa9 + 5a7c47a commit 127c9c3

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

cpp/0021-merge-two-sorted-lists.cpp

+3-11
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,8 @@ class Solution {
3131
return list1;
3232
}
3333

34-
ListNode* head = NULL;
35-
if (list1->val <= list2->val) {
36-
head = list1;
37-
list1 = list1->next;
38-
} else {
39-
head = list2;
40-
list2 = list2->next;
41-
}
42-
ListNode* curr = head;
43-
34+
ListNode* dummy = new ListNode();
35+
ListNode *curr = dummy;
4436
while (list1 != NULL && list2 != NULL) {
4537
if (list1->val <= list2->val) {
4638
curr->next = list1;
@@ -58,6 +50,6 @@ class Solution {
5850
curr->next = list1;
5951
}
6052

61-
return head;
53+
return dummy->next;
6254
}
6355
};

python/0128-longest-consecutive-sequence.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def longestConsecutive(self, nums: List[int]) -> int:
33
numSet = set(nums)
44
longest = 0
55

6-
for n in nums:
6+
for n in numSet:
77
# check if its the start of a sequence
88
if (n - 1) not in numSet:
99
length = 1

0 commit comments

Comments
 (0)