标签:
Invert Binary Tree
问题:
Invert a binary tree.
4 / 2 7 / \ / 1 3 6 9
to
4 / 7 2 / \ / 9 6 3 1
思路:
简单的递归
我的代码:
public class Solution { public TreeNode invertTree(TreeNode root) { helper(root); return root; } public void helper(TreeNode root) { if(root == null) return; TreeNode left = root.left; TreeNode right = root.right; root.left = right; root.right = left; helper(left); helper(right); } }
标签:
原文地址:http://www.cnblogs.com/sunshisonghit/p/4579956.html