diff --git a/Graphs/3Sum.cpp b/Graphs/3Sum.cpp new file mode 100644 index 0000000..b229851 --- /dev/null +++ b/Graphs/3Sum.cpp @@ -0,0 +1,47 @@ +class Solution { +public: + vector> threeSum(vector& arr) { + /* + for (int i = 0; i < n; i++) { + set hashset; + for (int j = i + 1; j < n; j++) { + int third = -(arr[i] + arr[j]); + if (hashset.find(third) != hashset.end()) { + vector temp = {arr[i], arr[j], third}; + sort(temp.begin(), temp.end()); + st.insert(temp); + } + hashset.insert(arr[j]); + } + } + + + vector> ans(st.begin(), st.end()); + return ans; + */ + int n=arr.size(); + sort(arr.begin(), arr.end()); + set> st; + vectortemp; + int sum=0; + for(int i=0;i0){ + k--; + } + else{ + j++; + } + } + } + vector> ans(st.begin(), st.end()); + return ans; + } +};