Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- using namespace std;
- /*
- this fucntion will return the pair of index which addation is equal to target value,
- is sum of the any pair of index is not matches with the target value <-1, -1> pair will be return as an info.
- */
- pair<int , int> f(vector<int>& nums , int target)
- {
- size_t size = nums.size();
- for (int i= 0; i <= size ; i++)
- {
- for (int j = i ; j< size; j++)
- if (nums[i] + nums[j] == target)
- return make_pair(i, j) ;
- }
- cout << "no sum is equal to the target number :" << target << endl;
- return make_pair(-1,-1);
- }
- int main()
- {
- vector<int> n = {2,7,11,15, 55,33,36,89,45,75,65} ;
- int target = 105;
- pair<int, int> index_position = f(n, target);
- cout << index_position.first << endl;
- cout << index_position.second << endl;
- return 0;
- }
Advertisement
Comments
-
- Input: nums = [2,5,7,13], target = 9 Output: [0,2] Explanation: Because nums[0] + nums[2] == 9, we return [0, 2].
Add Comment
Please, Sign In to add comment
Advertisement