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.
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.
总结(思路)
计数 + 从小到大配对:
- 若
changed长度为奇数直接空数组; - 统计频次(或排序后双指针 / 哈希)。
- 按值从小到大遍历
x:需要用count[x]去匹配2x的count[2x](特别注意x==0要偶数个)。 - 每匹配一次,将
x放入结果并减少对应频次;若不足则失败。
时间 O(n log n)(排序版),空间 O(n)。
The VOprep team has long accompanied candidates through various major company OAs and VOs, including NVIDIA, Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for Stripe or similar engineering-focused companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.