Skip to content

Commit

Permalink
Time: 49 ms (40.55%) | Memory: 12.6 MB (63.14%) - LeetSync
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad-Ikrash committed Mar 11, 2024
1 parent aa33098 commit f244766
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 1-two-sum/two-sum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public:
vector<int> twoSum(vector<int>& nums, int target) {
int size = nums.size();
vector <int> ans;
for (int i = 0; i < size - 1;i++){
vector <int>:: iterator pres = find(nums.begin() + i + 1, nums.end(), target - nums[i]);
if (pres != nums.end()) {
ans.push_back(i), ans.push_back(pres - nums.begin());
return ans;
}
}
return ans;
}
};

0 comments on commit f244766

Please sign in to comment.