码迷,mamicode.com
首页 > 其他好文 > 详细

Distinct

时间:2015-07-25 15:13:25      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

 1         /// <summary>
 2         /// Solution A
 3         /// 通过率 100%
 4         /// </summary>
 5         /// <param name="A"></param>
 6         /// <returns></returns>
 7         public static int solution(int[] A)
 8         {
 9             if (A.Length == 0) return 0;
10             int result = 1;
11             Array.Sort(A);
12             for (int i = 1; i < A.Length; i++)
13             {
14                 if (A[i] != A[i - 1])
15                     result++;
16             }
17             return result;
18         }
19 
20         /// <summary>
21         /// Solution B
22         /// 通过率 100%
23         /// </summary>
24         /// <param name="A"></param>
25         /// <returns></returns>
26         public static int solution(int[] A)
27         {
28             HashSet<int> hs = new HashSet<int>();
29             foreach (int num in A)
30             {
31                 hs.Add(num);
32             }
33             return hs.Count;
34         }

 

Distinct

标签:

原文地址:http://www.cnblogs.com/HuoAA/p/4675824.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!