leetcode-21Merge Two Sorted Lists
2015-06-25 16:01
344 查看
带头结点
import java.util.* ; class ListNode { int val; ListNode next; ListNode(int x) { val = x; } } public class Solution { public ListNode mergeTwoLists(ListNode l1, ListNode l2) { ListNode head = new ListNode(0) ; ListNode now = head ; while(l1 != null && l2 != null){ if(l1.val <= l2.val){ now.next = new ListNode(l1.val) ; l1 = l1.next ; } else{ now.next = new ListNode(l2.val) ; l2 = l2.next ; } now = now.next ; } while(l1 != null){ now.next = new ListNode(l1.val) ; l1 = l1.next ; now = now.next ; } while(l2 != null){ now.next = new ListNode(l2.val) ; l2 = l2.next ; now = now.next ; } return head.next ; } public static void main(String[] args){ } }
相关文章推荐
- Cortex_m3的启动过程
- [ext/iconv/iconv.lo] Error 1
- 用FLASH,安智和IOS打电话方法
- 一个异步任务的梳理
- 设计模式-观察者模式
- -Dmaven.multiModuleProjectDirectory system propery is not set.
- 经典开源C/C++项目
- 漫谈:机器学习中距离和相似性度量方法
- 秒杀多线程
- Win7如何还原系统默认的照片查看器让其以默认方式打开图片
- Android fragment生命周期
- Tomcat8配置SSL/TSL,Android通过HTTPS进行访问
- Android使用sharesdk一键分享
- android style 退出动画 解决退出动画无效问题
- asp.net后台获取使用js方法input文本的value
- 神经网络训练中的Tricks之高效BP(反向传播算法)
- .net中使用XPath语言在xml中判断是否存在节点值的方法
- MySql查询数据库的大小
- android file.createnewfile ioexception
- 白话经典算法