Tree Balanced
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
Given a binary tree. Determine if it is height-balanced. A height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differs by more than 1.
Definition of a tree:
// Java class TreeNode { public: int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; left = NULL; right = NULL; };
// C++ class TreeNode { public: int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) {} };
Implement function isBalanced that returns true if the tree is balanced and false otherwise.
// Java boolean isBalanced(TreeNode tree)
// C++ bool isBalanced(TreeNode *tree)
Example
Function isBalanced returns true because tree is balanced.
Submissions 1K
Acceptance rate 47%