fork download
  1. #include <iostream>
  2. #include<vector>
  3. using namespace std;
  4. class Solution {
  5. public:
  6. vector<vector<int>> threeSum(vector<int>& nums) {
  7. // create a vector which stores the index of the elements which forms the sum equal to zero
  8. vector<vector<int>> res;
  9.  
  10. // Run the loop for the given equation
  11. // create a function which stores the
  12. for(int l=0;l<nums.size()-2;l++){
  13. // Run the another loop for the given problems
  14. for(int m=l+1;m<nums.size()-1;m++){
  15. // Run another loop for the given problems
  16. for(int n=m+1;n<nums.size();n++){
  17. // cout<<"l: "<< l <<" m: "<< m <<" n: "<< n<<endl;
  18. if(l!=m && l!=n && m!=n){
  19. int sum=nums[l]+nums[m]+nums[n];
  20. if(sum==0){
  21. vector<int> v;
  22. v.push_back(nums[l]);
  23. v.push_back(nums[m]);
  24. v.push_back(nums[n]);
  25. res.push_back(v);
  26.  
  27. }
  28.  
  29.  
  30. }
  31. }
  32. }
  33. }
  34. return res;
  35. }
  36. };
  37. int main() {
  38. // your code goes here
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
Standard output is empty