Friday, 1 February 2019

LeetCode Q015 3Sum

Q015 3Sum



Similar to two sum if sort the array first
 Requires one more loop on the sorted array
 Check for every num in the array, can we find two sum that equals to - num

 Tricks:
 remove the duplicate target num, by checking if the previous == num  continue
 remove the duplicate left/right point, by shifting until find a different one from the previous

https://github.com/Sylvia-YiyinShen/Algorithm/blob/master/TwoPointers/Q015ThreeSum.playground/Contents.swift

No comments:

Post a Comment