PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#this is solved here
#https://www.sololearn.com/en/compiler-playground/c93Tz8I87eXF
import heapq
class Node:
def __init__(self, d):
self.data = d
self.next = None
self.bottom = None
class Solution:
def flatten(self, root):
if not root:
return None
pq = []
cur = root
while cur:
heapq.heappush(pq, (cur.data, cur))
cur = cur.next
last = Node(-1)
ans = last
while pq:
val, cur = heapq.heappop(pq)
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run