@anku There is no need to consider the duplicates of numbers , only index i, j, k are different is enough.
C
Chen_Xiang
@Chen_Xiang
0
Reputation
17
Posts
211
Profile views
0
Followers
0
Following
Posts made by Chen_Xiang

RE: 3Sum Smaller

RE: 3Sum Smaller
I have a question for the twoSumSmaller:
private int twoSumSmaller(int[] nums, int startIndex, int target) { int sum = 0; for (int i = startIndex; i < nums.length  1; i++) { int j = binarySearch(nums, i, target  nums[i]); sum += j  i; } return sum; }
Why we use binary search for target  nums[i] from index i, rather than i+1? I think we need to find the right most position after i, then it is
int j = binarySearch(nums, i+1, target  nums[i]);
, but the answer is wrong. Thx!