Should give three ways, by the tags
First time write binary search, but can be optimized.
Faults
- When comparing sorted array, I only considered the equal condition of two numbers, while the bigger and smaller can be used as the increment condition as well.
- Under this situation –>,
if (array1[i] < array2[j])
or something, the increment must be executed after the assertion thati < array1.size() and j < array2.size()
- –> If we don’t want duplicate element in the result, we can use set to hold the result, rather than checking the last element in the result.
- Under this situation –>,