21. Merge Two Sorted Lists
2016-04-15 16:38
337 查看
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
public class Solution{ public ListNode mergeTwoLists(ListNode l1, ListNode l2){ ListNode start; if (l1 == null) return l2; if (l2 == null) return l1; //对输入进行最简单的判断,这已经是一个必须的步骤了~ if (l1.val < l2.val){ start = l1; start.next = mergeTwoLists(l1.next, l2); } else { start = l2; start.next = mergeTwoLists(l1, l2.next); } //对数据判断然后递归~ return start; } }又是一道水题~
相关文章推荐
- 历年noip,apio题目考点
- AlertDialog二次点击报You must call removeView() on the child's parent first错的解决方法
- grunt 单独压缩多个js和css文件【转】
- 数据结构之C语言实现哈夫曼树
- ArcCatalog连接远程ArcGIS Server服务器
- IOS读取项目中的plist
- C++之include<iostream>与include<iostream.h>
- FreeSwitch呼入和呼出冲突的问题。
- java动态拼接datagrid的columns
- Android之登陆样式(仿知乎)
- MD5CryptoServiceProvider的MD5加密结果和百度不一致
- 简单的阶乘
- 第七周&第八周周记
- 软件工程课堂练习
- percona
- 分类添加属性,运行时添加对象属性和基本类型属性
- Spring MVC国际化的总结
- 如何实现一个原质化菜单项或按钮HTML5动画效果
- eclipse无法启动的各种解决方法
- markdown语法整理