Invert Binary Tree
Question
Invert a binary tree.
Example:
4
/ \
2 7
/ \ / \
1 3 6 9 4
/ \
7 2
/ \ / \
9 6 3 1Answer
solution:
Knowledge:
这道题目出现在了数据挖掘的面试题里面,因此值得重视。
这道题目一开始就知道是递归,但是在思考和编程过程的时候遇到点小问题,就是递归程序写法:1.先写出整个具体操作过程以及用等号划出需要递归的部分。2.确定函数return的返回形式。3.递归位置的形式一定是"参数=函数"的形式:4.可能之前一些位置的语句也要被递归形式代替"参数=函数"。
Last updated
Was this helpful?