Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BalancedTree {
- public static void main(String[] args) {
- TreeNode node = null;
- System.out.println(cheeckTree(node));
- }
- public static Boolean cheeckTree(TreeNode root) {
- if (root == null) {
- return false;
- }
- return Math.abs(getHeight(root.left) - getHeight(root.right)) < 2;
- }
- public static int getHeight(TreeNode root) {
- if (root == null) {
- return 0;
- }
- return Math.max(getHeight(root.left), getHeight(root.right)) + 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement