# Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.

# Note: The solution set must not contain duplicate triplets.

# For example, given array S = [-1, 0, 1, 2, -1, -4],

# A solution set is:
# [
#   [-1, 0, 1],
#   [-1, -1, 2]
# ]


@@ -295,24 +295,26 @@
 is:%0A# %5B%0A#   
+  
 %5B-1, 0, 1%5D,%0A
@@ -314,16 +314,18 @@
 0, 1%5D,%0A#
+  
    %5B-1, 
@@ -336,8 +336,1015 @@
 2%5D%0A# %5D%0A%0A
+class Solution(object):%0A    def threeSum(self, nums):%0A        %22%22%22%0A        :type nums: List%5Bint%5D%0A        :rtype: List%5BList%5Bint%5D%5D%0A        Sort the list; for each unique number, find two other numbers with %0A        two-pointers method.%0A        %22%22%22%0A        nums, result, i = sorted(nums), %5B%5D, 0%0A        while i %3C len(nums) - 2:%0A            if i %3E 0 and nums%5Bi%5D == nums%5Bi - 1%5D:%0A                i += 1%0A                continue%0A            j, k = i + 1, len(nums) -1%0A            while j %3C k:%0A                sum_ijk = nums%5Bi%5D + nums%5Bj%5D + nums%5Bk%5D%0A                if sum_ijk == 0:%0A                    result.append(%5Bnums%5Bi%5D, nums%5Bj%5D, nums%5Bk%5D%5D)%0A                    j, k = j + 1, k - 1%0A                    while j %3C k and nums%5Bj%5D == nums%5Bj - 1%5D:%0A                        j += 1%0A                    while j %3C k and nums%5Bk%5D == nums%5Bk + 1%5D:%0A                        k -= 1%0A                elif sum_ijk %3C 0:%0A                    j += 1%0A                else:%0A                    k -= 1%0A            i += 1%0A        return result

add 15.3Sum.py: n^2 method using two pointers