💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
![](https://box.kancloud.cn/79055bc56e0734fbb8ffef38ccefd615_572x484.png) ``` 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 } } ```