-
Notifications
You must be signed in to change notification settings - Fork 33
Add LeetCode-1 (different approach) and LeetCode-167 in C++ #46
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
Conversation
Update with the upstream branch
Add leetcode-1, leetcode-167
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @r8025n
Please resolve all the requested changes. Also, change the folder name from 167_TwoSum II
to 167_TwoSumII
class Solution { | ||
public: | ||
vector<int> twoSum(vector<int>& numbers, int target) { | ||
int index1 = 0, index2 = numbers.size()-1, sum; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this code to
int index1 = 0, index2 = numbers.size() - 1, sum;
public: | ||
vector<int> twoSum(vector<int>& numbers, int target) { | ||
int index1 = 0, index2 = numbers.size()-1, sum; | ||
vector<int> returnVector; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name the variable returnVector
to answer
and change in other places
class Solution { | ||
public: | ||
vector<int> twoSum(vector<int>& nums, int target) { | ||
vector<pair<int,int>> valueIndexPair; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this code to
vector<pair<int, int>> valueIndexPair;
public: | ||
vector<int> twoSum(vector<int>& nums, int target) { | ||
vector<pair<int,int>> valueIndexPair; | ||
vector<int> returnVector; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change the variable name returnVector
to answer
and also, change in other places where returnVector
has been used. Additionally, fix the indentation.
vector<int> twoSum(vector<int>& nums, int target) { | ||
vector<pair<int,int>> valueIndexPair; | ||
vector<int> returnVector; | ||
int index1, index2, sum; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the indentation.
int index1, index2, sum; | ||
|
||
for(int k = 0; k < nums.size(); k++) { | ||
valueIndexPair.push_back(pair<int,int>(nums[k], k)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this code to
valueIndexPair.push_back(pair<int, int>(nums[k], k));
|
||
sort(valueIndexPair.begin(), valueIndexPair.end()); | ||
|
||
index1 = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix indentation
sort(valueIndexPair.begin(), valueIndexPair.end()); | ||
|
||
index1 = 0; | ||
index2 = valueIndexPair.size() - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix indentation
while(index1 < index2) { | ||
sum = valueIndexPair[index1].first + valueIndexPair[index2].first; | ||
|
||
if(sum == target) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix indentation
HI, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @r8025n
Please fix all the indentation issues.
public: | ||
vector<int> twoSum(vector<int>& nums, int target) { | ||
vector<pair<int, int>> valueIndexPair; | ||
vector<int> answer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to fix the indentation.
vector<int> twoSum(vector<int>& nums, int target) { | ||
vector<pair<int, int>> valueIndexPair; | ||
vector<int> answer; | ||
int index1, index2, sum; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to fix the indentation.
|
||
sort(valueIndexPair.begin(), valueIndexPair.end()); | ||
|
||
index1 = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to fix the indentation.
sort(valueIndexPair.begin(), valueIndexPair.end()); | ||
|
||
index1 = 0; | ||
index2 = valueIndexPair.size() - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to fix the indentation.
else | ||
index2--; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to fix the indentation of the if-else block.
Hi @Tahanima What I did so far:
So did I miss any steps after pushing the first requested changes to my forked repo? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@r8025n I get your point. No worries. I'll fix the indentation issue (if there is any) after merging. Keep up the good work! 😃
Thank You :) |
resolves #42