Skip to content

Commit 2736169

Browse files
author
Amogh Singhal
authored
Update intersection_arrays.py
1 parent 8afa77f commit 2736169

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

intersection_arrays.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
# common elements between them
44
# Constraints: in O(m+n) complexity.
55

6-
76
def inr(z):
87
return z + 1
98

10-
119
def intersectionArrays(x, y, m, n):
1210
i, j = 0, 0
11+
intersect_arr = []
12+
1313
while i < m and j < n:
1414
# print(i, j)
1515
if x[i] == y[j]:
16-
print(x[i])
17-
i = inr(i)
18-
j = inr(j)
16+
intersect_arr.append(x[i])
17+
i, j = inr(i), inr(j)
1918
elif x[i] < y[j]:
2019
i = inr(i)
2120
else:
22-
j = inr[j]
23-
21+
j = inr(j)
22+
print(intersect_arr)
23+
return
2424

2525
list_a = [1, 2, 3, 4, 5]
2626
list_b = [2, 3, 5, 6]

0 commit comments

Comments
 (0)