Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def merge(self,a,b,m,n):
- nex=lambda x:x//2+(x%2) if x>1 else 0 #This is very important
- gap=nex(m+n)
- def swap(x,y,a,b):
- a[x],b[y]=b[y],a[x]
- while gap:
- i,j=0,gap
- while j<m+n:
- if i<m and j<m:
- if a[i]>a[j]:swap(i,j,a,a)
- elif i<m and j>=m:
- if a[i]>b[j-m]:swap(i,j-m,a,b)
- elif i>=m and j>=m:
- if b[i-m]>b[j-m]:swap(i-m,j-m,b,b)
- i,j=i+1,j+1
- gap=nex(gap)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement