java.lang.Object
g2001_2100.s2007_find_original_array_from_doubled_array.Solution

public class Solution extends Object
2007 - Find Original Array From Doubled Array.<p>Medium</p> <p>An integer array <code>original</code> is transformed into a <strong>doubled</strong> array <code>changed</code> by appending <strong>twice the value</strong> of every element in <code>original</code>, and then randomly <strong>shuffling</strong> the resulting array.</p> <p>Given an array <code>changed</code>, return <code>original</code> <em>if</em> <code>changed</code> <em>is a <strong>doubled</strong> array. If</em> <code>changed</code> <em>is not a <strong>doubled</strong> array, return an empty array. The elements in</em> <code>original</code> <em>may be returned in <strong>any</strong> order</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> changed = [1,3,4,2,6,8]</p> <p><strong>Output:</strong> [1,3,4]</p> <p><strong>Explanation:</strong> One possible original array could be [1,3,4]:</p> <ul> <li> <p>Twice the value of 1 is 1 * 2 = 2.</p> </li> <li> <p>Twice the value of 3 is 3 * 2 = 6.</p> </li> <li> <p>Twice the value of 4 is 4 * 2 = 8.</p> </li> </ul> <p>Other original arrays could be [4,3,1] or [3,1,4].</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> changed = [6,3,0,1]</p> <p><strong>Output:</strong> []</p> <p><strong>Explanation:</strong> changed is not a doubled array.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> changed = [1]</p> <p><strong>Output:</strong> []</p> <p><strong>Explanation:</strong> changed is not a doubled array.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= changed.length <= 10<sup>5</sup></code></li> <li><code>0 <= changed[i] <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • findOriginalArray

      public int[] findOriginalArray(int[] changed)