Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- [10, 20, 30, 40, 50]
- [15, 20, 35, 50, 76, 190]
- idx_a 2
- idx_b 2
- --> [20, 50]
- [10, 20]
- []
- --> []
- """
- def intersect_lists(list_a, list_b):
- idx_a, idx_b = 0, 0
- result = []
- while idx_a < len(list_a) and idx_b < len(list_b):
- num_a, num_b = list_a[idx_a], list_b[idx_b]
- if num_a == num_b:
- result.append(num_a)
- idx_a += 1
- idx_b += 1
- elif num_a < num_b:
- idx_a += 1
- else:
- idx_b += 1
- return result
- print(intersect_lists([10, 20, 30, 40, 50], [15, 20, 35, 50, 76, 190]))
- print(intersect_lists([10, 20], []))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement