- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.TwoSum.cpp
28 lines (27 loc) · 825 Bytes
/
1.TwoSum.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
///
/// LeetCode
/// By Reza Ebrahimi <reza.ebrahimi.dev@gmail.com>
///
/// Two Sum Problem
/// https://leetcode.com/problems/two-sum
///
/// Time Submitted | Status | Runtime | Memory | Language
/// 2020/03/10 | Accepted | 132 ms | 8.7 MB | cpp
///
/// Runtime: 132 ms, faster than 34.54% of C++ online submissions for Two Sum.
/// Memory Usage: 8.7 MB, less than 100.00% of C++ online submissions for Two Sum.
///
classSolution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
for (int i = 0; i < nums.size(); ++i) {
for (int j = i + 1; j < nums.size(); ++j) {
if (nums[i] + nums[j] == target) {
vector<int> twoSum = {i, j};
return twoSum;
}
}
}
return vector<int>();
}
};