<jupyter_start><jupyter_text>3 Sum[原题](https://mp.weixin.qq.com/s/0KPgom-f4syRJbG3EZslvQ)  QuestionGiven an array `nums` of $n$ integers, find all unique triplets (three numbers, $a$, $b$, & $c$) in `nums` such that $a+b+c=0$. Note that there may not be any triplets that sum to zero in `nums`, and that the triplets must not be duplicates.  Example```textInput: nums = [0, -1, 2, -3, 1]Output: [0, -1, 1], [2, -3, 1]```<jupyter_code>''' Class Definition '''
class Solution(object):
    def threeSum(self, nums: list):
        # Define a result list.
        result = []
        
        # Sort the list ascending.
        nums.sort()
        
        # Define 2 index pointer.
        minimum = 0
        maximum = len(nums) - 1
        
        # Keep checking until 2 index meet each other.
        while minimum < maximum:
            # Check if the triplets exists.
            is_exist = (-(nums[minimum] + nums[maximum]) in nums)

            if is_exist:
                index = nums.index(-(nums[minimum] + nums[maximum]))
                if index != minimum and index != maximum:
                    result.append([
                        nums[minimum],
                        -(nums[minimum] + nums[maximum]),
                        nums[maximum]
                    ])
            if nums[minimum] + nums[maximum] > 0:
                maximum -= 1
            elif nums[minimum] + nums[maximum] < 0:
                minimum += 1
        return result
''' Test Program '''
nums = [1, -2, 1, 0, 5]
print(Solution().threeSum(nums))
# [[-2, 1, 1]]<jupyter_output>[[-2, 1, 1]]
{'fraction_non_alphanumeric': 0.13682219419924338, 'fraction_numerical': 0.022068095838587643, 'mean_word_length': 1.8188277087033748, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '496317', 'license': 'MIT', 'n_tokens_mistral': 547, 'n_tokens_neox': 496, 'n_words': 150, 'path': 'February/Week8/51.ipynb', 'repo_name': 'Dragon1573/Daily-Problem', 'size': '1586'}