Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • iapyyk/leetles
1 result
Show changes
Commits on Source (4)
# Write a function solve that returns the running sum of a list.
# The running sum is the sum of all elements up to each index.
def solve(nums):
result = [nums[0]]
for i in range(1, len(nums)):
result.append(result[i - 1] + nums[i])
return result
\ No newline at end of file
# Write a function solve that reverses the words in a string.
# Words are separated by spaces.
def solve(string):
list = reversed(string.split())
return ' '.join(list)
\ No newline at end of file
# Write a function solve that rotates an n x n matrix 90 degrees clockwise in-place.
def solve(matrix):
for i in range(int(len(matrix))):
for j in range(i):
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
for list in matrix:
list.reverse()
return matrix
# Write a function solve that counts the number of vowels (a,e,i,o,u) in a string, ignoring case.
def solve(string):
counter = 0
vowels = ["a","e","i","o","u"]
for char in string.lower():
if char in vowels:
counter += 1
return counter
# 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
# 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