Ŀ
Ķ任ΪԴľ
##
ľ壺
Դ
8
/ \
6 10
/ \ / \
5 7 9 11
8
/ \
10 6
/ \ / \
11 9 7 5
##
Դľ
##Ŀ
ڵ
public class TreeNode {
int val = 0;
TreeNode left = null;
TreeNode right = null;
public TreeNode(int val) {
this.val = val;
}
}
ⷨʱ䣺38ms ռڴ棺688k
public class Solution {
public void Mirror(TreeNode root) {
if(root==null) return;
//ӽڵ
TreeNode tempNode;
tempNode = root.left;
root.left = root.right;
root.right = tempNode;
Mirror(root.left);
Mirror(root.right);
}
}
˼·Ӹڵ㿪ʼεݹڵ㲻Ϊգͽӽڵ㣨ĸֵӦָҲı䣩