2007. Find Original Array From Doubled Array Medium

@problem@discussion
#Array#Hash Table#Greedy#Sorting



1/**
2 * [2007] Find Original Array From Doubled Array
3 *
4 * An integer array original is transformed into a doubled array changed by appending twice the value of every element in original, and then randomly shuffling the resulting array.
5 * Given an array changed, return original if changed is a doubled array. If changed is not a doubled array, return an empty array. The elements in original may be returned in any order.
6 *  
7 * Example 1:
8 * 
9 * Input: changed = [1,3,4,2,6,8]
10 * Output: [1,3,4]
11 * Explanation: One possible original array could be [1,3,4]:
12 * - Twice the value of 1 is 1 * 2 = 2.
13 * - Twice the value of 3 is 3 * 2 = 6.
14 * - Twice the value of 4 is 4 * 2 = 8.
15 * Other original arrays could be [4,3,1] or [3,1,4].
16 * 
17 * Example 2:
18 * 
19 * Input: changed = [6,3,0,1]
20 * Output: []
21 * Explanation: changed is not a doubled array.
22 * 
23 * Example 3:
24 * 
25 * Input: changed = [1]
26 * Output: []
27 * Explanation: changed is not a doubled array.
28 * 
29 *  
30 * Constraints:
31 * 
32 * 	1 <= changed.length <= 10^5
33 * 	0 <= changed[i] <= 10^5
34 * 
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/find-original-array-from-doubled-array/
39// discuss: https://leetcode.com/problems/find-original-array-from-doubled-array/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44    pub fn find_original_array(changed: Vec<i32>) -> Vec<i32> {
45        vec![]
46    }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn test_2007() {
57    }
58}
59


Back
© 2025 bowen.ge All Rights Reserved.