Skip to content

Commit

Permalink
977
Browse files Browse the repository at this point in the history
  • Loading branch information
isinsuarici committed Apr 23, 2022
1 parent 5f5c291 commit 598a1bd
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions E_977_SquaresofaSortedArray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class Solution:
def mergeSort(self,array):
if len(array) > 1:
r = len(array)//2
L = array[:r]
M = array[r:]
self.mergeSort(L)
self.mergeSort(M)
i = j = k = 0
while i < len(L) and j < len(M):
if L[i] < M[j]:
array[k] = L[i]
i += 1
else:
array[k] = M[j]
j += 1
k += 1
while i < len(L):
array[k] = L[i]
i += 1
k += 1
while j < len(M):
array[k] = M[j]
j += 1
k += 1
return array

def sortedSquares(self, array: List[int]) -> List[int]:
for el in range(0,len(array)):
array[el]=array[el]**2
array=self.mergeSort(array)
return array






0 comments on commit 598a1bd

Please sign in to comment.