Reference: LeetCode
Difficulty: Medium
My Post: [Java] It’s Easy Because It Allows Duplicate Results!
Problem
Given an array of
nintegersnumsand atarget, find the number of index tripletsi,j,kwith0 <= i < j < k < nthat satisfy the conditionnums[i] + nums[j] + nums[k] < target.
Note: We also count the duplicate pairs!
Example:
1  | Input: nums = [-2,0,1,3], and target = 2  | 
Follow up: Could you solve it in $O(N^2)$ runtime?
Analysis
Two Pointers
1  | public int threeSumSmaller(int[] nums, int target) {  | 
Time: $O(N^2)$
Space: $O(1)$