MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / twoSum

Method twoSum

C++/two-sum.cpp:4–16  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2class Solution {
3public:
4 vector<int> twoSum(vector<int>& nums, int target) {
5 vector<int> v(2);
6 for(int i = 0; i<nums.size(); i++){
7 for(int j = i+1; j<nums.size();j++){
8 if(nums[j] == target-nums[i]){
9 v[0] = i;
10 v[1] = j;
11 return v;
12 }
13 }
14 }
15 return v;
16 }
17};
18
19// Above solution is of O(n^2) time complexity

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected