public class Solution {
public TreeNode invertTree(TreeNode tn){
if(tn == null) return null;
Stack<TreeNode> tnStack = new Stack<TreeNode>();
tnStack.push(tn);
while(!tnStack.isEmpty()){
TreeNode cur = tnStack.pop();
TreeNode temp = cur.left;
cur.left = cur.right;
cur.right = temp;
if(cur.left != null) tnStack.push(cur.left);
if(cur.right != null) tnStack.push(cur.right);
}
return tn;
//0726
}
}
2025 - 快车库 - 我的知识库 重庆启连科技有限公司 渝ICP备16002641号-10
企客连连 表单助手 企服开发 榜单123