Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
3Sum
Array Alchemist
Jul 17, 2024
118 views
3Sum
#Leetcode #blind75 #array
Hint
Given an integer array nums, return all the triplets
[nums[i], nums[j], nums[k]]
such thati != j
,i != k
, andj != k
, andnums[i] + nums[j] + nums[k] == 0
.Notice that the solution set must not contain duplicate triplets.
In a simple word given an array, we need to find three numbers in the array that adds up to 0.
Example 1:
Before we dwelve to solve the problem. Let's first take time why is it important?
The why?
Why even bother to solve this problem?
5. Uber:
This is why it's important to understand this algorithm.
first before we solve a three sum problem , let's revise how we can solve two sum problem.
now's let see if we can break down any pattern to solve the 3 sum problem.
Next:
so now we can refactor our algorithm to
This is how the problem can be solved.