Imports System
Imports System.Collections.Generic
Public Class Program
Private Shared Function twoSum(ByVal array As Integer(), ByVal target As Integer) As Integer()
Dim hmap As IDictionary(Of Integer, Integer) = New Dictionary(Of Integer, Integer)()
For i As Integer = 0 To array.Length - 1
Dim complement As Integer = target - array(I)
If hmap.ContainsKey(complement) Then
Return New Integer() {hmap(complement), i}
Else
hmap(array(i)) = i
End If
Next
Return New Integer() {}
End Function
Public Shared Sub Main(ByVal args As String())
Dim array As Integer() = New Integer() {1, 5, 7, 6, 4, 3, 2}
Dim target As Integer = 9
Dim indexes As Integer() = twoSum(array, target)
If indexes.Length = 2 Then
Console.WriteLine(indexes(0) & " " & indexes(1))
Else
Console.WriteLine("Not found")
End If
End Sub
End Class
' run:
'
' 1 4
'