Back to course home
0% completed
Vote For New Content
My python solution.
Eric Imho Jang
Jul 26, 2024
class Solution: def searchTriplets(self, arr, target): count = 0 arr.sort() for i in range(len(arr)-1): fix = i left = i+1 right = len(arr)-1 while left < right: sum = arr[fix] + arr[left] + arr[right] diff = target - sum if diff > 0: right -= 1 count += 1 elif diff < 0: right -= 1 elif diff == 0: right -= 1 if left < len(arr)-2 and left >= right: left += 1 right = len(arr)-1 return count
0
0
Comments
Comments
On this page
Problem Statement
Try it yourself