当前位置:网站首页>JZ27 二叉树的镜像
JZ27 二叉树的镜像
2022-08-02 15:35:00 【syc596】
JZ27 二叉树的镜像
二叉树的镜像_牛客题霸_牛客网 (nowcoder.com)
//11
//自顶向下递归
import java.util.*;
public class Solution {
public TreeNode Mirror (TreeNode root) {
if(root==null){
return null;
}
TreeNode tmp=root.left;
root.left=root.right;
root.right=tmp;
Mirror(root.left);
Mirror(root.right);
return root;
}
}
// //栈
// import java.util.*;
// public class Solution {
// public TreeNode Mirror (TreeNode root) {
// if(root==null){
// return null;
// }
// Stack<TreeNode> st=new Stack<>();
// st.push(root);
// while(st.isEmpty()==false){
// TreeNode cur=st.pop();
// if(cur.left!=null){
// st.push(cur.left);
// }
// if(cur.right!=null){
// st.push(cur.right);
// }
// TreeNode tmp=cur.left;
// cur.left=cur.right;
// cur.right=tmp;
// }
// return root;
// }
// }边栏推荐
猜你喜欢
随机推荐
不平衡之钥: 重采样法何其多
System delay tasks and scheduled tasks
06-线程池(3大方法、7大参数,4种拒绝策略)
Qt | 模态对话框和非模态对话框 QDialog
多商户商城系统功能拆解20讲-平台端分销概况
轻松入门自然语言处理系列 专题8 源码解读──基于HMM的结巴分词
【wpf】ListView 和 ItemsControl 的一点区别
VPP snort插件
制胜精细化运营时代 华为应用市场打出内容、场景、商业运营组合拳
ACL/NAACL'22 推荐系统论文梳理
机械臂速成小指南(十七):直线规划
MySQL【数据类型】
CefSharp practical demonstration
面试官:可以谈谈乐观锁和悲观锁吗
从幻核疑似裁撤看如何保证NFT的安全
Qt | 关于样式表的使用 QStyleSheet
关于小程序TabBar跳转页面跟TabBar标签栏的icon不对应的分析(debug)
Go-5-简单介绍fmt库
Basic management of system storage -- mounts, partitions, user quotas
节省50%成本!京东云重磅发布新一代混合CDN产品









