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