LeetCode 147 Insertion Sort List
2015-12-02 09:15
495 查看
题目描述
Sort a linked list using insertion sort.代码
[code] public ListNode insertionSortList(ListNode head) { if (head == null) return null; if (head.next == null) return head; final ListNode _head = new ListNode(Integer.MIN_VALUE); _head.next = head; head = head.next; _head.next.next = null; next: while (head != null) { ListNode taken = head; head = head.next; ListNode cur = _head.next; ListNode last = _head; while (cur != null) { if (cur.val > taken.val) { // insert last.next = taken; taken.next = cur; continue next; } cur = cur.next; last = last.next; } last.next = taken; taken.next = null; } return _head.next; }
相关文章推荐
- 基于tomcat7的websocket
- java中转发和重定向的区别
- android 圆形按钮
- oracle连接加号(+)的使用方法
- Android开发屏幕适配全攻略
- CGFloat、CGPoint、CGSize和CGRect
- 【代码笔记】按钮带下划线的写法
- 拼图响应式前端框架版响应式后台正式发布。
- java中的class 与Class , A.class 与 A.getClass() 到底有什么 不同
- Android样式的开发:drawable汇总篇
- 记一个百度地图导航中存在的bug
- 【代码笔记】按钮带下划线的写法
- Java学习之多态
- asp.net 操作word 权限
- eclipse下使用tomcat启动maven项目
- bootstrap中的媒体对象
- 《C语言入门经典》Ivor Horton第十章练习题3
- 【LeetCode】 Reverse Words in a String
- HR筛选简历逃不过这5点
- 《事情正在起变化》《这是为什么》?