forked from illuz/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTLE_bruteforce_n2.cpp
45 lines (40 loc) · 1.06 KB
/
TLE_bruteforce_n2.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
43
44
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: tle_bruteforce_n2.cpp
* Create Date: 2014-11-26 10:44:37
* Descripton: brute force: O(n*n), TLE
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 0;
class Solution {
public:
vector<int> twoSum(vector<int> &numbers, int target) {
int sz = numbers.size();
vector<int> index;
for (int i = 0; i < sz; i++)
for (int j = i + 1; j < sz; j++)
if (numbers[i] + numbers[j] == target) {
index.push_back(i + 1);
index.push_back(j + 1);
return index;
}
// Program never go here, because
// "each input would have exactly one solution"
}
};
int main() {
Solution s;
vector<int> in;
int n, t;
cin >> n;
while (n--) {
cin >> t;
in.push_back(t);
}
cin >> t;
in = s.twoSum(in, t);
cout << in[0] << ' ' << in[1] << endl;
return 0;
}