Super easy to understand C++ Code, beat 100%
Idea is straight forward - try every possible k.\n1. First we sort array and get minimum value - minV in this array, then try all possible high value of minV to
Idea is straight forward - try every possible k.\n1. First we sort array and get minimum value - minV in this array, then try all possible `high` value of minV to calculate k.\nTo get k, minV plus its high value s hould be even, and k can only be larger than 0.\n2. Then we need to verify if k is valid. Here I use a `used` vector to make sure we didn\'t use same index again, then use just two pointers to iterate the sorted array. If we can\'t find matching, just break and try other k.\n3. During iteration, fill in result array. If we can iterate `n` times, then we found the result.\n\n```\nclass Solution {\npublic:\n    bool kernel(int n, vector<int>& nums, int k, vector<bool>& used, vector<int>& result){\n        int k2 = k + k;\n        int i = 0;\n        int lIndex = 0;\n        int hIndex = 0;\n        int v1, v2, v;\n        int n2 = n * 2;\n        for(; i < n; i++){\n            while(lIndex < n2 && used[lIndex]){\n                lIndex++;\n            }\n            if(lIndex == n2){\n                break;\n            }\n            v1 = nums[lIndex];\n            used[lIndex] = true;\n            v = v1 + k2;\n            while(hIndex < n2 && (used[hIndex] || nums[hIndex] != v)){\n                hIndex++;\n            }\n            if(hIndex == n2){\n                break;\n            }\n            used[hIndex] = true;\n            result[i] = v1 + k;\n        }\n        \n        return i == n;\n    }\n    vector<int> recoverArray(vector<int>& nums) {\n        sort(begin(nums), end(nums));\n        \n        int n = nums.size() / 2;\n        int minV = nums[0];\n        vector<int> result(n);\n        int total = n + n;\n        vector<bool> used(total);\n        for(int i = 1; i <= n; i++){\n            if((minV + nums[i]) % 2 == 0){\n                int k = (nums[i] - minV) / 2;\n                if(k == 0){\n                    continue;\n                }\n                fill(begin(used), end(used), false);\n                bool found = kernel(n, nums, k, used, result);\n                if(found){\n                    break;\n                }    \n            }\n        }\n        \n        return result;\n    }\n};\n```
['Two Pointers', 'Greedy', 'C']