Lintcode 375.克隆二叉树
2024-10-13 22:30:22
--------------------------
水题
AC代码:
/**
* Definition of TreeNode:
* public class TreeNode {
* public int val;
* public TreeNode left, right;
* public TreeNode(int val) {
* this.val = val;
* this.left = this.right = null;
* }
* }
*/
public class Solution {
/**
* @param root: The root of binary tree
* @return root of new tree
*/
public TreeNode cloneTree(TreeNode root) {
if(root==null) return null;
TreeNode copycat=new TreeNode(root.val);
copycat.left=cloneTree(root.left);
copycat.right=cloneTree(root.right);
return copycat;
}
}
题目来源: http://www.lintcode.com/zh-cn/problem/clone-binary-tree/#
最新文章
- IE浏览器版本判断 HTML代码
- css整理-02 颜色和字体
- RabbitMQ学习笔记3-使用topic交换器
- CSS3小分队——进击的border-radius
- 转:21副GIF动图让你了解各种数学概念
- sublimeformaya
- POJ 1778 All Discs Considered(拓扑排序)
- iOS APP之本地数据存储(译)
- UILabel自适应高度,自动换行
- springmvc中关于静态资源的放行
- jQuery Easy UI Resizable(调整大小)组件
- Linux下查找大文件以及目录
- js转base64(数字)
- 一文搞懂TCP与UDP的区别
- PYthon3:函数实现“自动售卖机”功能
- C# Window Service安装、卸载、恢复选项操作
- [nodejs] nodejs开发个人博客(三)载入页面
- u-boot移植(十三)---代码修改---裁剪及环境变量 二
- Windows远程桌面,连接被拒绝,因为没有授权此用户帐户进行远程登录。
- Android实现动态改变屏幕方向(Landscape &; Portrait)