Two Sum
Last updated
Last updated
Given an array of integers
nums
and an integertarget
, return indices of the two numbers such that they add up totarget
.You may assume that each input would have exactly** one solution**, and you may not use the same element twice.
You can return the answer in any order.
Loops through the array once - O(N)
Map operations are constant time
Total - O(N)
Stores complement of each element in a Map
Worst case scenario is that complement is in the last position of the array
Total - O(N)