题目及测试
package pid114;
/*114. 二叉树展开为链表
给定一个二叉树,原地将它展开为一个单链表。
例如,给定二叉树
1
/ \
2 5
/ \ \
3 4 6
将其展开为:
1
\
2
\
3
\
4
\
5
\
6
*/
public class main {
public static void main(String[] args) {
Object[] x=new Object[]{1,2,5,3,4,null,6};
BinaryTree tree=new BinaryTree(x);
BinaryTree.printTree(tree.root);
test(tree.root);
}
private static void test(TreeNode ito) {
Solution solution = new Solution();
long begin = System.currentTimeMillis();
solution.flatten(ito);//执行程序
long end = System.currentTimeMillis();
System.out.println();
System.out.println("rtn=" );
BinaryTree.printTree(ito);
System.out.println();
System.out.println("耗时:" + (end - begin) + "ms");
System.out.println("-------------------");
}
}
解法1(成功