Content-Length: 1624 | pFad | http://github.com/fishercoder1534/Leetcode/pull/103.diff
thub.com
diff --git a/cpp/3-Sum.cpp b/cpp/3-Sum.cpp
new file mode 100644
index 0000000000..1c99b34de1
--- /dev/null
+++ b/cpp/3-Sum.cpp
@@ -0,0 +1,47 @@
+class Solution {
+public:
+ vector> threeSum(vector& nums) {
+
+ //
+ vector> res;
+ //sort
+ sort(nums.begin(),nums.end());
+
+ for(unsigned int i = 0; i < nums.size();i++){
+ // initialize left and right
+ //to handle duplicates
+ if(i > 0 && nums[i]==nums[i-1])
+ continue;
+ int l = i + 1;
+ int r = nums.size() - 1;
+ int x = nums[i];
+
+ while (l < r)
+ {
+ if (x + nums[l] + nums[r] == 0) {
+ res.push_back(vector{x,nums[l],nums[r]});
+ //to handle duplicates
+ while (l
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/fishercoder1534/Leetcode/pull/103.diff
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy