标签:void col oid else bsp roo span ide rev
1 class Solution { 2 TreeNode newRoot; 3 TreeNode prev; 4 public TreeNode upsideDownBinaryTree(TreeNode root) { 5 if(root == null) return root; 6 helper(root); 7 return newRoot; 8 } 9 10 public void helper(TreeNode root){ 11 if(root.left != null){ 12 helper(root.left); 13 }else{ 14 newRoot = new TreeNode(root.val); 15 prev = newRoot; 16 return; 17 } 18 if(root.right != null){ 19 prev.left = new TreeNode(root.right.val); 20 } 21 prev.right = new TreeNode(root.val); 22 prev = prev.right; 23 } 24 }
标签:void col oid else bsp roo span ide rev
原文地址:https://www.cnblogs.com/goPanama/p/10090807.html