LeetCode 18 | 4Sum | Solution Explained (Java + Whiteboard)

preview_player
Показать описание
Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.

Note:

The solution set must not contain duplicate quadruplets.

Example:

Given array nums = [1, 0, -1, 0, -2, 2], and target = 0.

A solution set is:
[
[-1, 0, 0, 1],
[-2, -1, 1, 2],
[-2, 0, 0, 2]
]

Running Time: O(n^3)
Space Complexity: O(n)

Рекомендации по теме
Комментарии
Автор

This 12 minutes video is way better than 20 minutes videos ..
the way of explanation of your thought process while coding is amazing ...
Subscribed :)

-Corvo_Attano
Автор

If you guys have any questions or want me to post any solutions to problems let me know below :)

xavierelon
Автор

wow! super clear explanation! Thanks a lot

andreymasunov
Автор

Great explanation
it will be great if you take a any problem of leetcode and explain specific problem in higher to lower time complexity

pallavijadhav
Автор

You are great at explaining....Thank you so much!!

ashisenchoudhury
Автор

I still don't understand when we check duplicates in if(sum == target), then use nums[right] == nums[right+1], I think it's right-1? but right-1 doesn't work if submit

frankf
Автор

The video was good but a little more explanation of the theory behind the sum on the whiteboard would be highly appreciated.

JRK_RIDES
visit shbcf.ru