diff --git a/cpp/0001-two-sum.cpp b/cpp/0001-two-sum.cpp index 5ce94c170..557be7bf4 100644 --- a/cpp/0001-two-sum.cpp +++ b/cpp/0001-two-sum.cpp @@ -24,3 +24,45 @@ class Solution { return {}; } }; + +/* + APPROACH-2: Sorting + Two Pointer + Store the given array in vector of pairs {{value,index}, {value,index}}.... + Then sort the vector of pair.. + After sorting we can apply two pointer aproach. + + Time Complexity: O(nlogn) + Space Complexity: O(n); +*/ + +class Solution2{ +public: + + vector twoSum(vector& nums, int target) { + vector> array; + int len = nums.size(); + for(int i=0; i