Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution for twosum #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/TwoSum/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Reverse Integer

LeetCode [source](https://leetcode.com/problems/two-sum/)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a Solution with Intuition, Algorithm and Complexity Analysis like README.md.

## AC Result

| Status | Runtime | Memory |
|--------|---------|--------|
| Accepted | 364 ms | 9.3 MB |
Zhongnibug marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 43 additions & 0 deletions src/TwoSum/Solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <iostream>
#include <vector>
#include <unordered_map>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used?


using namespace std;

class Solution{
public:
vector<int> twoSum(vector<int> nums, int target){

vector<int> result;
int second_number;

for(int i=0; i<nums.size()-1; i++){
for(int j=i+1; j<nums.size(); j++){
if (target == nums[i]+nums[j]){
result.push_back(i);
result.push_back(j);
}
}
}

return result;
}
};



int main(int argc, char const *argv[]){

Solution s;

vector<int> nums;
nums.push_back(3);
nums.push_back(2);
nums.push_back(4);

int target = 6;

vector<int> result = s.twoSum(nums, target);
cout<<result[0]<<" "<<result[1];
return 0;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last line should have a newline character.