update
swadhinbiswas committed 2 years ago
d407eda
1 parent 74b485a
commit d407eda
2 files changed
+23 -3
Showing 2 changed files+23-3
▼.gitignore
+3-1
| @@ -157,4 +157,6 @@ cython_debug/ | ||
157 | 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore |
158 | 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear |
159 | 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. |
160 | -#.idea/ | |
160 | +.idea/ | |
161 | +.conda/ | |
162 | +.vscode/ | |
161 | 163 | |
▼marge2shortedlist.py
+20-2
| @@ -1,5 +1,23 @@ | ||
1 | -from typing import Optional,ListNode | |
1 | +from typing import Optional | |
2 | + | |
3 | + | |
4 | +class ListNode: | |
5 | + def __init__(self, val=0, next=None): | |
6 | + self.val = val | |
7 | + self.next = next | |
8 | + | |
2 | 9 | |
3 | 10 | class Solution: |
4 | 11 | def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]: |
5 | - pass | |
12 | + if not list1: | |
13 | + return list2 | |
14 | + if not list2: | |
15 | + return list1 | |
16 | + if list1.val < list2.val: | |
17 | + list1.next = self.mergeTwoLists(list1.next, list2) | |
18 | + return list1 | |
19 | + else: | |
20 | + list2.next = self.mergeTwoLists(list1, list2.next) | |
21 | + return list2 | |
22 | + | |
23 | + | |
6 | 24 | |