Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- #Function to return the count of number of elements in union of two arrays.
- def doUnion(self,a,m,b,n):
- a.sort()
- b.sort()
- i=j=0
- t=[]
- while i<m and j<n:
- if a[i]<b[j]:
- if not t or (t and a[i]!=t[-1]) :
- t.append(a[i])
- i=i+1
- elif a[i]>b[j]:
- if not t or (t and b[j]!=t[-1]) :
- t.append(b[j])
- j=j+1
- else:
- if not t or (t and a[i]!=t[-1]) :
- t.append(a[i])
- i,j=i+1,j+1
- while i<m:
- if not t or (t and a[i]!=t[-1]) :
- t.append(a[i])
- i=i+1
- while j<n:
- if not t or (t and b[j]!=t[-1]) :
- t.append(b[j])
- j=j+1
- return len(t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement