Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 316c6bf

Browse filesBrowse files
authored
Create Two_Sum.cpp
Solution to the LeetCode problem "Two Sum" #1
1 parent b846e98 commit 316c6bf
Copy full SHA for 316c6bf

File tree

1 file changed

+17
-0
lines changed
Filter options

1 file changed

+17
-0
lines changed

‎Two_Sum.cpp

Copy file name to clipboard
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <vector>
2+
using namespace std;
3+
4+
class Solution {
5+
public:
6+
vector<int> twoSum(vector<int>& nums, int target) {
7+
int len = nums.size();
8+
for (int i = 0; i < len; i++) {
9+
for (int j = i + 1; j < len; j++) {
10+
if (nums[i] + nums[j] == target) {
11+
return {i, j};
12+
}
13+
}
14+
}
15+
return {};
16+
}
17+
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.