diff --git a/lectures/20-trees/code/AVL/AVL.java b/lectures/20-trees/code/AVL/AVL.java index b3080fcd3..a4a988947 100644 --- a/lectures/20-trees/code/AVL/AVL.java +++ b/lectures/20-trees/code/AVL/AVL.java @@ -90,8 +90,8 @@ public Node rightRotate(Node p) { c.right = p; p.left = t; - p.height = Math.max(height(p.left), height(p.right) + 1); - c.height = Math.max(height(c.left), height(c.right) + 1); + p.height = Math.max(height(p.left), height(p.right)) + 1; + c.height = Math.max(height(c.left), height(c.right)) + 1; return c; } @@ -103,8 +103,9 @@ public Node leftRotate(Node c) { p.left = c; c.right = t; - p.height = Math.max(height(p.left), height(p.right) + 1); - c.height = Math.max(height(c.left), height(c.right) + 1); + + c.height = Math.max(height(c.left), height(c.right)) + 1; + p.height = Math.max(height(p.left), height(p.right)) + 1; return p; } @@ -159,4 +160,4 @@ private boolean balanced(Node node) { return Math.abs(height(node.left) - height(node.right)) <= 1 && balanced(node.left) && balanced(node.right); } -} \ No newline at end of file +}