Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5c93988

Browse files
add build_linked_list
1 parent 56d52e4 commit 5c93988

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Python/common_utils.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@ def print_linked_list(head):
1515
node = node.next
1616
print(s)
1717

18+
19+
def build_linked_list(arr):
20+
head = node = None
21+
for val in arr:
22+
if head is None:
23+
head = node = ListNode(val)
24+
else:
25+
node.next = ListNode(val)
26+
node = node.next
27+
return head
28+
29+
1830
class Interval:
1931
def __init__(self, s=0, e=0):
2032
self.start = s
21-
self.end = e
33+
self.end = e

0 commit comments

Comments
 (0)