Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Lowest Common Ancestor algorithm #258

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updata lowest common ancestor.js
orist22 committed Dec 5, 2018
commit 5c6b4f23e42f7676fa8642e284e658a42c63721e
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ export default function lca(rootNode, firstNode, secondNode) {
const firstDepth = calcDepth(firstNode);
const secondDepth = calcDepth(secondNode);

for (int i = 0; i < Math.abs(firstDepth - secondDepth); i++) {
for (let i = 0; i < Math.abs(firstDepth - secondDepth); i++) {
if (firstDepth > secondDepth)
firstNode = firstNode.parent;
else