Skip to content

Commit f087adf

Browse files
Two sum (#50)
* two-sum.cpp added * Comments added
1 parent c5b1198 commit f087adf

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

C++/two-sum.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Brute force solution
2+
class Solution {
3+
public:
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+
};

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
9999
| 1572 | [Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum/) | [Java](./Java/matrix-diagonal-sum.java) | _O(N)_ | _O(1)_ | Easy | | |
100100
| 811 | [Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count/) | [Javascript](./JavaScript/Subdomain-Visit-Count.js) | _O(N*M)_ | _O(N*M + N)_ | Easy | | |
101101
| 53 | [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/) | [C++](./C++/maximum-subarray.cpp) | _O(N)_ | _O(1)_ |Easy | Array | |
102+
| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | [C++](./C++/two-sum.cpp) | _O(N^2)_ | _O(1)_ |Easy | Array | |
102103

103104
<br/>
104105
<div align="right">
@@ -356,6 +357,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if
356357
| [Nour Grati](https://github.com/Nour-Grati) <br> <img src="https://github.com/Nour-Grati.png" width="100" height="100"> | Tunisia | Python | [Leetcode](https://leetcode.com/nourgrati/) <br> [Hackerrank](https://www.hackerrank.com/noor_grati) <br> [Twitter](https://twitter.com/GratiNour1)
357358
|[Avinash Trivedi](https://github.com/trivediavinash) <br> <img src="https://github.com/trivediavinash.png" width="100" height="100"> |India | C++ | [Leetcode](https://leetcode.com/avi_002/) |
358359
|[Ishika Goel](https://github.com/ishikagoel5628) <br> <img src="https://github.com/Nour-Grati.png" width="100" height="100"> | India | C++ | [Leetcode](https://leetcode.com/ishikagoel5628/) |
360+
|[Prashansa Tanwar](https://github.com/prashansatanwar) <br> <img src="https://github.com/prashansatanwar.png" width="100" height="100"> | India | C++ | [Leetcode](https://leetcode.com/prashansaaa/) |
359361

360362
<br/>
361363
<div align="right">

0 commit comments

Comments
 (0)