【Video】Simple Solution
\n# Solution Video\n\nhttps://youtu.be/0TjQLNfQ3jc\n\n### \u2B50\uFE0F\u2B50\uFE0F Don\'t forget to subscribe to my channel! \u2B50\uFE0F\u2B50\uFE0F\n\n\u25A0 
\n# Solution Video\n\nhttps://youtu.be/0TjQLNfQ3jc\n\n### \u2B50\uFE0F\u2B50\uFE0F Don\'t forget to subscribe to my channel! \u2B50\uFE0F\u2B50\uFE0F\n\n**\u25A0 Subscribe URL**\nhttp://www.youtube.com/channel/UC9RMNwYTL3SXCP6ShLWVFww?sub_confirmation=1\n\nSubscribers: 6,628\nThank you for your support!\n\n---\n\n```python []\nclass Solution:\n    def fourSum(self, nums: List[int], target: int) -> List[List[int]]:\n        nums.sort()\n        res = []\n\n        for i in range(len(nums) - 3):\n            # skip duplicate starting values\n            if i > 0 and nums[i] == nums[i-1]:\n                continue\n            \n            for j in range(i+1, len(nums) - 2):\n                # skip duplicate starting values\n                if j > i + 1 and nums[j] == nums[j-1]:\n                    continue\n                left, right = j + 1, len(nums) - 1\n\n                while left < right:\n                    four_sum = nums[i] + nums[j] + nums[left] + nums[right]\n                    if four_sum == target:\n                        res.append([nums[i], nums[j], nums[left], nums[right]])\n                        left += 1\n                        right -= 1\n\n                        while left < right and nums[left] == nums[left - 1]:\n                            left += 1\n                        while left < right and nums[right] == nums[right + 1]:\n                            right -= 1\n                    elif four_sum < target:\n                        left += 1\n                    else:\n                        right -= 1\n        return res\n```\n```javascript []\n/**\n * @param {number[]} nums\n * @param {number} target\n * @return {number[][]}\n */\nvar fourSum = function(nums, target) {\n    const result = [];\n\n    if (nums == null || nums.length < 4) {\n        return result;\n    }\n\n    nums.sort((a, b) => a - b);\n    const len = nums.length;\n    \n    for (let i = 0; i < len - 3; i++) {\n        if (i > 0 && nums[i] == nums[i-1]) {\n            continue;\n        }\n        for (let j = i+1; j < len - 2; j++) {\n            if (j > i+1 && nums[j] == nums[j-1]) {\n                continue;\n            }\n            let left = j + 1;\n            let right = len - 1;\n            while (left < right) {\n                const sum = nums[i] + nums[j] + nums[left] + nums[right];\n                \n                if (sum == target) {\n                    result.push([nums[i], nums[j], nums[left], nums[right]]);\n\n                    while (left < right && nums[left] == nums[left+1]) {\n                        left++;\n                    }\n\n                    while (left < right && nums[right] == nums[right-1]) {\n                        right--;\n                    }\n\n                    left++;\n                    right--;\n                } else if (sum < target) {\n                    left++;\n                } else {\n                    right--;\n                }\n            }\n        }\n    }\n\n    return result\n};\n```\n\n---\n\n\n\n# \u2B50\uFE0F Subscribe URL\nhttp://www.youtube.com/channel/UC9RMNwYTL3SXCP6ShLWVFww?sub_confirmation=1\n\n# \u2B50\uFE0F Twitter\nhttps://twitter.com/CodingNinjaAZ\n\n# \u2B50\uFE0F My previous video\n#28 - Longest Consecutive Sequence \n\nhttps://youtu.be/PRVmb_7u6fo
['Python3', 'JavaScript']