The deduplication method of the double cycle is as follows:
- Use two pointers i and j, respectively pointing to the elements in the two arrays
- If the i-th element of array 1 is the same as the j-th element of array 2, delete the j-th element of array 2
- If the i-th element of array 1 is not the same as the j-th element of array 2, move the pointer j one bit backward
- When j reaches the end of array 2, move the i pointer back one bit, and continue to repeat the above steps
The specific code is as follows:
for(int i=0; i<array1.length; i++) {
for(int j=0; j<array2.length; j++) {
if(array1[i] == array2[j]) {
// 删除数组2的第j个元素
}
}
}
Hope this helps you!