mirror of
https://github.com/20kaushik02/leetcode-gulag.git
synced 2026-01-25 07:34:05 +00:00
some more neetcode
This commit is contained in:
11
1-two-sum/driver.cpp
Normal file
11
1-two-sum/driver.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "soln.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
vector<int> nums{2, 7, 11, 15};
|
||||
int target = 9;
|
||||
vector<int> answer{0, 1};
|
||||
Solution soln;
|
||||
cout << "Found two-sum indices correctly? " << soln.test(nums, target, answer) << endl;
|
||||
return 0;
|
||||
}
|
||||
24
1-two-sum/soln.cpp
Normal file
24
1-two-sum/soln.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "soln.hpp"
|
||||
|
||||
vector<int> Solution::twoSum(vector<int> &nums, int target)
|
||||
{
|
||||
vector<int> result(2);
|
||||
for (int i = 0; i < nums.size(); i++)
|
||||
{
|
||||
for (int j = i + 1; j < nums.size(); j++)
|
||||
{
|
||||
if (nums[i] + nums[j] == target)
|
||||
{
|
||||
result[0] = i;
|
||||
result[1] = j;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Solution::test(vector<int> &nums, int target, vector<int> &answer)
|
||||
{
|
||||
return twoSum(nums, target) == answer;
|
||||
}
|
||||
8
1-two-sum/soln.hpp
Normal file
8
1-two-sum/soln.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
class Solution
|
||||
{
|
||||
public:
|
||||
vector<int> twoSum(vector<int> &nums, int target);
|
||||
bool test(vector<int> &nums, int target, vector<int> &answer);
|
||||
};
|
||||
Reference in New Issue
Block a user