Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import defaultdict
- class Solution:
- def bottomView(self, root):
- q=deque()
- q.append((root,0))
- d=defaultdict(list)
- while q:
- for _ in range(len(q)):
- t,v=q.popleft()
- d[v].append(t.data)
- if t.left:q.append((t.left,v-1))
- if t.right:q.append((t.right,v+1))
- ans=[]
- for i in sorted(d.keys()):
- ans.append(d[i][-1])
- return ans
Advertisement
Add Comment
Please, Sign In to add comment