File tree 2 files changed +24
-1
lines changed
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 14
14
| 13 | [ Roman To Integer] ( https://leetcode.com/problems/roman-to-integer/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/RomanToInteger.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/roman_to_integer.py ) |
15
15
| 14 | [ Longest Common Prefix] ( https://leetcode.com/problems/longest-common-prefix/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/LongestCommonPrefix.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/longest_common_prefix.py ) |
16
16
| 20 | [ ValidParentheses] ( https://leetcode.com/problems/valid-parentheses/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/ValidParentheses.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/valid_parentheses.py ) |
17
- | 21 | [ Merge 2 Sorted Lists] ( https://leetcode.com/problems/merge-two-sorted-lists/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/Merge2SortedLists.java ) |
17
+ | 21 | [ Merge 2 Sorted Lists] ( https://leetcode.com/problems/merge-two-sorted-lists/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/Merge2SortedLists.java ) [ ![ Python ] ( https://img.icons8.com/color/35/000000/python.png )] ( python/merge_2_sorted_lists.py ) |
18
18
| 26 | [ Remove Duplicates From Sorted Array] ( https://leetcode.com/problems/remove-duplicates-from-sorted-array/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/RemoveDuplicatesFromSortedArray.java ) |
19
19
| 27 | [ Remove Element] ( https://leetcode.com/problems/remove-element/ ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/RemoveElement.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/remove_element.py ) |
20
20
| 28 | [ Needle in Haystack] ( https://leetcode.com/problems/implement-strstr ) | Easy | [ ![ Java] ( https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png )] ( src/NeedleInHaystack.java ) [ ![ Python] ( https://img.icons8.com/color/35/000000/python.png )] ( python/needle_in_haystack.py ) |
Original file line number Diff line number Diff line change
1
+ # Definition for singly-linked list.
2
+ class ListNode :
3
+ def __init__ (self , val = 0 , next = None ):
4
+ self .val = val
5
+ self .next = next
6
+
7
+
8
+ class Solution :
9
+ def mergeTwoLists (self , l1 : ListNode , l2 : ListNode ) -> ListNode :
10
+ result = ListNode (val = - 1 )
11
+ previous = result
12
+
13
+ while l1 is not None and l2 is not None :
14
+ if l1 .val <= l2 .val :
15
+ previous .next = l1
16
+ l1 = l1 .next
17
+ else :
18
+ previous .next = l2
19
+ l2 = l2 .next
20
+ previous = previous .next
21
+
22
+ previous .next = l2 if l1 is None else l1
23
+ return result .next
You can’t perform that action at this time.
0 commit comments