Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 2sum drill
- function main(x::Array{Int64, 1}, y::Int64)
- n = length(x)
- z = Array{Int64}(undef, n, 2)
- h = Array{UInt64}(undef, n)
- c = 0
- for i = 1:n
- xx = y - x[i]
- if xx in x
- temp = [x[i], xx]
- temp_ = [xx, x[i]]
- if !(hash(temp) in h[1:c]) && !(hash(temp_) in h[1:c])
- c += 1
- z[c,:] = temp
- h[c] = hash(temp)
- end
- end
- end
- if c > 0
- return z[1:c,:]
- else
- println("no pairs found!")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement