谁能解释用从左到右的随机指针克隆二叉树的方法?每个节点都有以下结构。
struct node {
int key;
struct node *left,*right,*random;
}
Run Code Online (Sandbox Code Playgroud)
这是一个非常受欢迎的面试问题,我能够根据散列(类似于链表的克隆)找出解决方案。我试图理解链接(方法 2)中给出的解决方案,但也无法通过阅读代码弄清楚它想传达什么。我不期望基于散列的解决方案,因为它直观且非常直接。请解释基于修改二叉树并克隆它的解决方案。
我们知道Integer类中的valueof值是静态的.但是当我们通过Integer类的对象调用时,它没有给出任何错误.例如:以下代码运行完美...
public class Test {
public static void main(String[] args)
{
Integer i=new Integer(5);
System.out.println(i.valueOf(i));
}
}
Run Code Online (Sandbox Code Playgroud)