书中的举例如下:
我写的代码是:
/** public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ public class Solution { public void Mirror(TreeNode root) { while(root.left!=null||root.right!=null){ TreeNode rootLeft = root.left; TreeNode rootRight = root.right; root.left = rootRight; root.right = rootLeft; while(root.left!=null){ System.out.println(root.left.val); Mirror(root.left); } while(root.right!=null){ System.out.println(root.right.val); Mirror(root.right); } } } }
结果一直输出11 跳不出循环 请问是为什么呢?
Caballarii
相关分类