내가 VB6에서 중복을 제거 느린이 기능을제거 빠른 VB6 복제
내가 더 빨리 실행하려면이 기능을 최적화해야Function FilterDuplicates(Arr As Variant) As Long
Dim col As Collection, index As Long, dups As Long
Set col = New Collection
On Error Resume Next
For index = LBound(Arr) To UBound(Arr)
' build the key using the array element
' an error occurs if the key already exists
col.Add 0, CStr(Arr(index))
If Err Then
' we've found a duplicate
Arr(index) = Empty
dups = dups + 1
Err.Clear
ElseIf dups Then
' if we've found one or more duplicates so far
' we need to move elements towards lower indices
Arr(index - dups) = Arr(index)
Arr(index) = Empty
End If
Next
' return the number of duplicates
FilterDuplicates = dups
End Function
, 내가 추가 내 대답을 업데이트
도움을 주시기 바랍니다가 마지막 비트. 그래도 숙제를해야할까요? –
아니 숙제가 아니지만 왜 그런 질문을 했습니까? – Smith