Tree: Height of a Binary Tree

Sort by

recency

|

992 Discussions

|

  • + 0 comments

    Java 8

    public static int height(Node root) {
            if(root==null){
            return -1;
            }
    
            int left = height(root.left);
            int right = height(root.right);
    
            return Math.max(left, right)+1;
    }
    
  • + 0 comments
    def height(root, prev=0):
        return max(height(root.left), height(root.right))+1 if root is not None and (root.left is not None or root.right is not None) else prev
    `
    
  • + 0 comments

    node:internal/streams/writable:474 throw new ERR_INVALID_ARG_TYPE( ^ TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (6) at _write (node:internal/streams/writable:474:13)

    getting this though solution is fine :/

  • + 0 comments

    I've consistently been getting "We couldn't process your submission" errors for a solution that passes all tests for several days in a row.

  • + 0 comments

    def height(root): if root is not None: left_height = height(root.left) right_height = height(root.right) return max(left_height, right_height) + 1 else: return -1

    py code