/** * @param {number[]} nums * @param {number} target * @return {number[][]} */ var fourSum = function (nums, target) {
nums = nums.sort((a, b) => (a - b)); let res = []; let len = nums.length; for (let i = 0; i < len - 2; i++) { if (i > 0 && nums[i] == nums[i - 1]) { continue; }
for (let j = i + 1; j < len - 2; j++) { if (j > i + 1 && nums[j] == nums[j - 1]) { continue; }
let firstNum = nums[i]; let secondNum = nums[j];
const restVal = target - firstNum - secondNum
let leftIndex = j + 1; let rightIndex = len - 1; while(leftIndex < rightIndex) { let sum = nums[leftIndex] + nums[rightIndex]; if (restVal === sum) {