有没有办法在调试时修改JavaScript代码?Visual Studio具有"编辑并继续",类似的热交换代码可以用Java和其他语言完成.这可以用JavaScript完成,如果是这样,怎么做?
我之前已经问过类似的问题,但我认为我的解决方案要简单得多.特别是与维基百科相比.
请证明我错了!
如果您的树具有具有给定数据结构的节点:
struct node
{
node * left;
node * right;
node * parent;
int key;
}
Run Code Online (Sandbox Code Playgroud)
你可以写一个这样的函数:
node* LCA(node* m, node* n)
{
// determine which of the nodes is the leftmost
node* left = null;
node* right = null;
if (m->key < n->key)
{
left = m;
right = n;
}
else
{
left = n;
right = m;
}
// start at the leftmost of the two nodes,
// keep moving up the tree …Run Code Online (Sandbox Code Playgroud)