上一篇的解决办法显然不是最优的,先在找到了一种最优的解决办法,利用Directory进行合并数组,去除重复项。
代码如下:
效果如下:
using
System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DouHaoCount
{
class Program
{
static void Main( string [] args)
{
long T1 = DateTime.Now.Ticks;
Dictionary < int , int > dic = new Dictionary < int , int > ();
int [] Arr1 = {58975个0 - 9的随机数};
int []Arr2 = {103991个0 - 9的随机数};
foreach ( int i in Arr1)
{
if ( ! dic.ContainsKey(i))
dic.Add(i, i);
}
foreach ( int i in Arr2)
{
if ( ! dic.ContainsKey(i))
dic.Add(i, i);
}
int [] Arr = new int [dic.Count];
int k = - 1 ;
foreach ( int item in dic.Keys)
{
k ++ ;
Arr[k] = item;
}
Array.Sort(Arr);
long T2 = DateTime.Now.Ticks;
foreach ( int t in Arr)
{
Console.WriteLine(t);
}
Console.WriteLine(( double )(T2 - T1) / 10000.0 + " 毫秒,Arr1元素个数: " + Arr1.Length + " ,Arr2个数: " + Arr2.Length);
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DouHaoCount
{
class Program
{
static void Main( string [] args)
{
long T1 = DateTime.Now.Ticks;
Dictionary < int , int > dic = new Dictionary < int , int > ();
int [] Arr1 = {58975个0 - 9的随机数};
int []Arr2 = {103991个0 - 9的随机数};
foreach ( int i in Arr1)
{
if ( ! dic.ContainsKey(i))
dic.Add(i, i);
}
foreach ( int i in Arr2)
{
if ( ! dic.ContainsKey(i))
dic.Add(i, i);
}
int [] Arr = new int [dic.Count];
int k = - 1 ;
foreach ( int item in dic.Keys)
{
k ++ ;
Arr[k] = item;
}
Array.Sort(Arr);
long T2 = DateTime.Now.Ticks;
foreach ( int t in Arr)
{
Console.WriteLine(t);
}
Console.WriteLine(( double )(T2 - T1) / 10000.0 + " 毫秒,Arr1元素个数: " + Arr1.Length + " ,Arr2个数: " + Arr2.Length);
Console.ReadLine();
}
}
}