Skip to content
Snippets Groups Projects
Commit f614b323 authored by Iida Pyykkönen's avatar Iida Pyykkönen
Browse files

18 and 20

parent 408a709c
Branches main
No related tags found
No related merge requests found
18.py 0 → 100644
# Write a function solve that generates the first n rows of Pascal's Triangle.
def solve(rows):
triangle = []
for i in range(0, rows):
row = []
row.append(1)
if i == 1:
row.append(1)
elif i > 1:
for j in range(0, i-1):
first = triangle[i-1][j]
second = triangle[i-1][j+1]
row.append(first + second)
row.append(1)
triangle.append(row)
return triangle
20.py 0 → 100644
# Write a function that, given the head of a singly linked list, reverses the list.
# Return the root node of the reversed list.
def solve(head):
current = head
prev = None
while current:
temp_next = current.next
current.next = prev
prev = current
current = temp_next
return prev
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment