-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTwo Sum .cpp
42 lines (25 loc) · 881 Bytes
/
Two Sum .cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
problem link :https://leetcode.com/explore/interview/card/top-interview-questions-easy/92/array/546/
problem name: Two Sum
status: accepted
author : moahnd sakr
** */
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
vector<int> vect;
vector<int> ::iterator it ;
int len=nums.size();
for(int i=0;i<len;i++){
int needed=target-nums[i];
it=find(nums.begin(),nums.end(),needed);
if(it!=nums.end()&&(it-nums.begin()!=i))
{
vect.push_back(i);
vect.push_back(it-nums.begin());
break;
}
}
return vect;
}
};