求1函数(获取数组中指定重出现次数的元素集)

求一函数(获取数组中指定重出现次数的元素集)
求一函数(获取数组中指定重出现次数的元素集)
如:a=1,2,2,3,3,4,4,4,5,5,5,6,6,6

指定取重复两次的元素:返回结果=2,3

------最佳解决方案--------------------
Imports System.IO
Imports System.Text.RegularExpressions

Module Module1
    Sub Main()
        Dim arr As Integer() = {1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}
        Dim dict As Dictionary(Of Integer, Integer) = GetRepeat(arr, 2)
        For Each key As Integer In dict.Keys
            Console.WriteLine(key.ToString() + "重复了" + dict(key).ToString() + "次")
        Next
        Console.ReadKey()
    End Sub

    Function GetRepeat(ByVal arr As Integer(), ByVal repeat As Integer) As Dictionary(Of Integer, Integer)
        Dim dict As New Dictionary(Of Integer, Integer)
        For Each i As Integer In arr
            If dict.ContainsKey(i) Then
                dict(i) = dict(i) + 1
            Else
                dict.Add(i, 1)
            End If
        Next
        Dim result As New List(Of Integer)
        For Each key As Integer In dict.Keys
            If dict(key) <> repeat Then result.Add(key)
        Next
        For Each key As Integer In result
            dict.Remove(key)
        Next
        Return dict
    End Function
End Module

------其他解决方案--------------------

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim arr As Integer() = {1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7}
        Console.WriteLine(GetValue(arr, 2))
    End Sub
        Private Function GetValue(ByVal arr() As Integer, ByVal count As Integer) As String