Solution for Scala


  • 0
    C
    object Main extends App {
      def rob(root: TreeNode): Int = {
        if (root == null) return 0
        return Math.max(
          rob(root.left) + rob(root.right),
          root.value +
            (if (root.left == null) 0 else rob(root.left.left) + rob(root.left.right)) +
            (if (root.right == null) 0 else rob(root.right.left) + rob(root.right.right))
        )
      }
    }
    

Log in to reply
 

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