Double for loop array deduplication

The deduplication method of the double cycle is as follows:

  1. Use two pointers i and j, respectively pointing to the elements in the two arrays
  2. 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
  3. 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
  4. 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!

Guess you like

Origin blog.csdn.net/weixin_35756690/article/details/128874065#comments_27599497