DEV Community

Miss Pooja Anilkumar Patel
Miss Pooja Anilkumar Patel

Posted on

2007. Leetcode solution in python

class Solution:
  def findOriginalArray(self, changed: List[int]) -> List[int]:
    ans = []
    q = deque()

    for num in sorted(changed):
      if q and num == q[0]:
        q.popleft()
      else:
        q.append(num * 2)
        ans.append(num)

    return [] if q else ans
Enter fullscreen mode Exit fullscreen mode

leetcode

challenge

here is the link for the problem:
https://leetcode.com/problems/find-original-array-from-doubled-array/

Top comments (0)