2010-4-12 面试题1
有两个有序整数数组,例如{1,3,5,7,9}和{2,4,6,7,8},设计一个函数使两个数组合并,并且剔除掉两个数组里重复的元素。
代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int[] numbers = { 4, 5, 6, 1, 2, 3, -2, -1, 0,100 };
int[] numbers2 = { 12, 22, 36, 55, 100 };
List<int> listInt = new List<int>();
listInt = numbers.Concat(numbers2).OrderBy(f=>f).Distinct().ToList();
foreach (int i in listInt)
{
System.Console.WriteLine(i);
}
Console.Read();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int[] numbers = { 4, 5, 6, 1, 2, 3, -2, -1, 0,100 };
int[] numbers2 = { 12, 22, 36, 55, 100 };
List<int> listInt = new List<int>();
listInt = numbers.Concat(numbers2).OrderBy(f=>f).Distinct().ToList();
foreach (int i in listInt)
{
System.Console.WriteLine(i);
}
Console.Read();
}
}
}