Problem
Given an array numbers consisting of integer elements and an array deleted indicating whether to remove each element, write a function solution that removes elements from numbers according to deleted and returns the resulting array.
- If
deleted[i]is1,numbers[i]is removed; if0,numbers[i]is kept.
Constraints
- Each element in
numbersis an integer with an absolute value not exceeding 500. numbersis not empty, and its length does not exceed 100.- Each element in
deletedis either1or0. - The length of
deletedis equal to the length ofnumbers.
Test Case
| Test Case Number | numbers | deleted | return |
|---|---|---|---|
| 1 | [1, 2, 3, 4] | [1, 0, 1, 0] | [2, 4] |
| 2 | [1, 2, 3, 4] | [0, 1, 0, 1] | [1, 3] |
| 3 | [-490, 0, 35, -1, 500, -24] | [1, 0, 0, 1, 1, 0] | [0, 35, -24] |
Explanation for Test Case 1
- Given
numbers = [1, 2, 3, 4]anddeleted = [1, 0, 1, 0], elements1and3are removed, resulting in[2, 4].
Explanation for Test Case 2
- Given
numbers = [1, 2, 3, 4]anddeleted = [0, 1, 0, 1], elements2and4are removed, resulting in[1, 3].
Explanation for Test Case 3
- Given
numbers = [-490, 0, 35, -1, 500, -24]anddeleted = [1, 0, 0, 1, 1, 0], elements-490,-1, and500are removed, resulting in[0, 35, -24].