My python solution .


  • 0
    K
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Author: kidjourney
    # @Date:   2015-05-15 16:37:58
    # @Last Modified by:   kidjourney
    # @Last Modified time: 2015-05-15 17:07:31
    # Definition for a binary tree node.
    # class TreeNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    
    class Solution:
        # @param {TreeNode} root
        # @return {integer[]}
        def rightSideView(self, root):
            if not root :
                return []
            self.anslist = [root.val]
            self.rdir = {}
            self.ldir = {}
            self.mrl(root.right,self.rdir,0)
            self.mrl(root.left,self.ldir,0)
            print (self.rdir)
            print (self.ldir)
            self.anslist += dict(list(self.ldir.items()) + list(self.rdir.items())).values()
            return self.anslist
    
        def mrl(self,node,ndir,deep) :
            if node :
                ndir.setdefault(deep,node.val)
            else :
                return 
            self.mrl(node.right,ndir,deep+1)
            self.mrl(node.left,ndir,deep+1)

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.