✔️ Clean and well structured Python3 implementation (Top 93.2%) || Very simple
I found this Github repository with solutions to Leetcode problems https://github.com/AnasImloul/Leetcode-solutions\nThe ability to find every solution in one l
I found this Github repository with solutions to Leetcode problems https://github.com/AnasImloul/Leetcode-solutions\nThe ability to find every solution in one location is very helpful, I hope it helps you too\n```\nclass Solution(object):\n    def recoverArray(self, nums):\n        nums.sort()\n        mid = len(nums) // 2\n        # All possible k are (nums[j] - nums[0]) // 2, otherwise there is no num that satisfies nums[0] + k = num - k.\n        # For nums is sorted, so that any 2 elements (x, y) in nums[1:j] cannot satisfy x + k = y - k.\n        # In other words, for any x in nums[1:j], it needs to find y from nums[j + 1:] to satisfy x + k = y - k, but\n        # unfortunately if j > mid, then len(nums[j + 1:]) < mid <= len(nums[1:j]), nums[j + 1:] are not enough.\n        # The conclusion is j <= mid.\n\t\t# If you think it\u2019s not easy to understand why mid is enough, len(nums) can also work well\n\t\t# for j in range(1, len(nums)):  \n        for j in range(1, mid + 1):  # O(N)\n            if nums[j] - nums[0] > 0 and (nums[j] - nums[0]) % 2 == 0:  # Note the problem described k is positive.\n                k, counter, ans = (nums[j] - nums[0]) // 2, collections.Counter(nums), []\n                # For each number in lower, we try to find the corresponding number from higher list.\n                # Because nums is sorted, current n is always the current lowest num which can only come from lower\n                # list, so we search the corresponding number of n which equals to n + 2 * k in the left\n                # if it can not be found, change another k and continue to try.\n                for n in nums:  # check if n + 2 * k available as corresponding number in higher list of n\n                    if counter[n] == 0:  # removed by previous num as its corresponding number in higher list\n                        continue\n                    if counter[n + 2 * k] == 0:  # not found corresponding number in higher list\n                        break\n                    ans.append(n + k)\n                    counter[n] -= 1  # remove n\n                    counter[n + 2 * k] -= 1  # remove the corresponding number in higher list\n                if len(ans) == mid:\n                    return ans\n\n```
['Python3']