|
190 | 190 | /** |
191 | 191 | * Finds a node by it's value in a given sub-tree. |
192 | 192 | * Average time complexity: O(log N). |
193 | | - * |
| 193 | + * |
194 | 194 | * @private |
195 | 195 | * @param {Number|String} Value of the node which should be found. |
196 | 196 | * @param {Node} Current node to be checked. |
|
221 | 221 | * @param {Node} oldChild Child to be replaced. |
222 | 222 | * @param {Node} newChild Child replacement. |
223 | 223 | */ |
224 | | - exports.BinaryTree.prototype._replaceChild = |
| 224 | + exports.BinaryTree.prototype._replaceChild = |
225 | 225 | function (parent, oldChild, newChild) { |
226 | 226 | if (!parent) { |
227 | 227 | this._root = newChild; |
|
254 | 254 | } |
255 | 255 |
|
256 | 256 | if (node._left && node._right) { |
257 | | - var min = this._findMin(node._right), |
258 | | - temp = node.value; |
| 257 | + var min = this._findMin(node._right); |
| 258 | + var temp = node.value; |
259 | 259 |
|
260 | 260 | node.value = min.value; |
261 | 261 | min.value = temp; |
|
362 | 362 | if (!root) { |
363 | 363 | return 0; |
364 | 364 | } |
365 | | - var leftHeight = this._getHeight(root._left), |
366 | | - rightHeight = this._getHeight(root._right), |
367 | | - path = leftHeight + rightHeight + 1; |
| 365 | + var leftHeight = this._getHeight(root._left); |
| 366 | + var rightHeight = this._getHeight(root._right); |
| 367 | + var path = leftHeight + rightHeight + 1; |
368 | 368 | return Math.max(path, getDiameter(root._left), getDiameter(root._right)); |
369 | 369 | }.bind(this); |
370 | 370 | return getDiameter(this._root); |
|
401 | 401 |
|
402 | 402 | exports.BinaryTree.prototype._lowestCommonAncestor = |
403 | 403 | function (firstNode, secondNode, current) { |
404 | | - var firstNodeInLeft = this._existsInSubtree(firstNode, current._left), |
405 | | - secondNodeInLeft = this._existsInSubtree(secondNode, current._left), |
406 | | - firstNodeInRight = this._existsInSubtree(firstNode, current._right), |
407 | | - secondNodeInRight = this._existsInSubtree(secondNode, current._right); |
| 404 | + var firstNodeInLeft = this._existsInSubtree(firstNode, current._left); |
| 405 | + var secondNodeInLeft = this._existsInSubtree(secondNode, current._left); |
| 406 | + var firstNodeInRight = this._existsInSubtree(firstNode, current._right); |
| 407 | + var secondNodeInRight = this._existsInSubtree(secondNode, current._right); |
408 | 408 | if ((firstNodeInLeft && secondNodeInRight) || |
409 | 409 | (firstNodeInRight && secondNodeInLeft)) { |
410 | 410 | return current; |
|
0 commit comments