Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- """
- :type nums1: List[int]
- :type m: int
- :type nums2: List[int]
- :type n: int
- :rtype: void Do not return anything, modify nums1 in-place instead.
- """
- def mergeSortedArray(self, A, m, B, n):
- # write your code here
- i = m+n-1 #A size
- j = m-1 #A
- u = n-1 #B
- if m == 0:
- for k in range(n):
- A[k] = B[k]
- elif n == 0:
- pass
- else:
- while i >=0:
- if B[u]>=A[j]:
- A[i] = B[u]
- i-=1
- if u==0:
- break
- else:
- u-=1
- else:
- A[i]=A[j]
- i-=1
- if j==0:
- while u>=0:
- A[i]=B[u]
- i-=1
- u-=1
- break
- else:
- j-=1
Add Comment
Please, Sign In to add comment