File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+
3
+ #include < algorithm>
4
+
5
+ using namespace std ;
6
+ // @leet start
7
+ class Solution {
8
+ public:
9
+ vector<int > twoSum (vector<int >& numbers, int target) {
10
+ set<int > s (numbers.begin (), numbers.end ());
11
+ map<int , vector<int >> m;
12
+ vector<int > res (2 );
13
+ for (int i = 0 ; i < (int )numbers.size (); i++) {
14
+ m[numbers[i]].push_back (i);
15
+ }
16
+
17
+ for (int i = 0 ; i < (int )numbers.size (); i++) {
18
+ int num1 = numbers[i];
19
+ int num2 = target - numbers[i];
20
+ if (num1 == num2 and (int ) m[num1].size () == 1 ) continue ;
21
+
22
+ if (s.count (num2)) {
23
+ res[0 ] = i + 1 ;
24
+ res[1 ] = m[num2][0 ] + 1 ;
25
+ }
26
+ }
27
+ sort (res.begin (), res.end ());
28
+ return res;
29
+ }
30
+ };
31
+ // @leet end
32
+
33
+ int main () { return 0 ; }
You can’t perform that action at this time.
0 commit comments