#I'm working on leetcode problem 15 "3Sum

1 messages · Page 1 of 1 (latest)

jaunty geyser
#

Hey I'm not too sure if you solved it. But the issue in your code lies in:

 while left < right and nums[left] != nums[left-1]:       # b/c prev left += 1
                        left += 1
                    while left < right and nums[right] != nums[right+1]:    # b/c prev right -= 1
                        right -= 1

It should be this:

 while left < right and nums[left] == nums[left-1]:       # b/c prev left += 1
                        left += 1
                    while left < right and nums[right] == nums[right+1]:    # b/c prev right -= 1
                        right -= 1

The issues lies with the condition "if the current left/right pointer is the NOT same as the last, move pointers. However, it should be the opposite. If the left/right pointer is pointing to the same thing, we need to skip over that

#

lmk if the explanation doesn't make sense