jwzxgo 发表于 2013-1-30 04:42
多谢 LZ 分享 copy the old tree 这个是什么意思哈?
其实我那时候更糊涂,不过我觉得应该是这个意思:
Writing down the implementation of the algorithm that does a copy of a binary search tree seems to be a task preferred by certain interviewers. Doing this task properly requires an understanding of both the tree traversal and referencing in Java. However, doing this task properly also requires only few lines of code (if done recursively). That said, I've included below the implementation of the algorithm that copies a binary search tree in O(n) runtime complexity (it can't get faster than that, as you have to traverse and copy all the nodes, don't you?). Here yo go: