C++ 4ms <99.88%, 9.1MB <94.74% 2 pointers within 2 for loops
Runtime: 4 ms, faster than 99.88% of C++ online submissions for 4Sum.\n* Memory Usage: 9.1 MB, less than 94.74% of C++ online submissions for 4Sum.\n\n\nstatic 
* Runtime: 4 ms, faster than 99.88% of C++ online submissions for 4Sum.\n* Memory Usage: 9.1 MB, less than 94.74% of C++ online submissions for 4Sum.\n\n```\nstatic auto x = []() {ios_base::sync_with_stdio(false); cin.tie(NULL); return NULL; }();\n\nclass Solution {\npublic:\nvector< vector<int> > fourSum(vector<int>& nums, int target) {\n\tvector< vector<int> > result;\n\tsize_t n = nums.size();\n\tif (n < 4) \treturn result;\n\n\n\tsort(nums.begin(), nums.end());\n\tfor (int i = 0; i < n-3; ++i) {\n\t\tif (target <= 0 && nums[i] > 0) break;\n\n\t\tif (nums[i] + nums[i+1] + nums[i+2] + nums[i+3] > target) break;\n\t\tif (nums[i] + nums[n-3] + nums[n-2] + nums[n-1] < target) continue; \n\t\tif (i > 0 && nums[i] == nums[i-1]) continue;\n\n\t\tfor (int j = i+1; j < n - 2; ++j) {\n\t\t\tif (nums[i] + nums[j] + nums[j+1] + nums[j+2] > target) break;\n\t\t\tif (nums[i] + nums[j] + nums[n-2] + nums[n-1] < target) continue; \n\t\t\tif (j > i+1 && nums[j] == nums[j-1]) continue;\n\n\t\t\tint left = j+1, right = n-1;\n\t\t\twhile (left < right) {\n\t\t\t\tint sum = nums[i] + nums[j] + nums[left] + nums[right];\n\t\t\t\tif (sum == target) \n                {\n\t\t\t\t\tresult.push_back({nums[i], nums[j], nums[left], nums[right]});\n\t\t\t\t\tint last_left = nums[left], last_right = nums[right];\n\t\t\t\t\twhile (left < right && nums[left] == last_left) ++left;\n\t\t\t\t\twhile (left < right && nums[right] == last_right) --right;\n\t\t\t\t} \n                else if (sum < target) { ++left; } \n                else { --right; }\n\t\t\t}\n\t\t}\n\t}\n\treturn result;\n}\n};\n```
['C++']