Skip to content

panda-saroj/two-sum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

two-sum

Given an array of integers, find two numbers such that they add up to a specific target number.

The given C++ solution, sorts the array(vector) and then checks the sum of first and last element of the sorted vector, comapres that with the target and if the sum is less than target then moves to the next element from first or else moves to the previous element from last. If sum matches with the target then the indices of the found numbers in the original vector are returned.

As sorting takes nlogn time. The time complexity of this solution is O(nlogn).

About

Given an array of integers, find two numbers such that they add up to a specific target number.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages