Solution: Sum of Three Values
Let's solve the 3Sum problem using the Two Pointers pattern.
Statement
Given an array of integers, nums
, and an integer value, target
, determine if there are any three integers in nums
whose sum is equal to the target
, that is, nums[i] + nums[j] + nums[k] == target
. Return TRUE if three such integers exist in the array. Otherwise, return FALSE.
Note: A valid triplet consists of elements with distinct indexes. This means, for the triplet
nums[i], nums[j]
, andnums[k]
,i
j
,i
k
andj
k
.
Constraints:
-
nums.length
-
nums[i]
-
target