思路:定义一个字典存储数组2,键为该元素,值为true,在字典中判断是否含有数组1中的元素键,不含有就存入一个List中,最后得到的List转为Array数组就是不含有数组2元素的新数组1,如果要删除字典中含有数组1的元素,只需要判断键值true或false即可。传统方法时间复杂度为n方,这种方法为2n。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sort : MonoBehaviour
{
int[] arr1 = new int[] {
1, 5, 6