【LeetCode with Python】 Reorder List
来源:互联网 发布:游戏程序员的职业诉求 编辑:程序博客网 时间:2024/06/07 01:32
博客域名:http://www.xnerv.wang
原题页面:https://oj.leetcode.com/problems/reorder-list/
题目类型:
难度评价:★
本文地址:http://blog.csdn.net/nerv3x3/article/details/37337343
原题页面:https://oj.leetcode.com/problems/reorder-list/
题目类型:
难度评价:★
本文地址:http://blog.csdn.net/nerv3x3/article/details/37337343
Given a singly linked list L: L0→L1→…→Ln-1→Ln,
reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…
You must do this in-place without altering the nodes' values.
For example,
Given {1,2,3,4}
, reorder it to {1,4,2,3}
.
class Solution: # @param head, a ListNode # @return nothing def reorderList(self, head): if None == head: return cur = head count = 0 while None != cur: cur = cur.next count += 1 if count <= 2: return half_count = (count - 1) / 2 cur2 = head for i in range(0, half_count): cur2= cur2.next cur2_next = cur2.next cur2.next = None cur2 = reverse_list(cur2_next, None, None) cur1 = head time_count = int(count / 2) for i in range(0, time_count): cur2_next = cur2.next cur2.next = cur1.next cur1.next = cur2 cur1 = cur2.next cur2 = cur2_next
0 0
- 【LeetCode with Python】 Reorder List
- 【leetcode】Reorder List (python)
- [Leetcode][python]Reorder List
- 【LEETCODE】143- Reorder List [Python]
- [LeetCode]--143. Reorder List(Python + Java)
- leetcode: Reorder List 的Python实现
- [leetcode][list] Reorder List
- [leetcode][list] Reorder List
- Leetcode: Reorder List
- [LeetCode] Reorder List
- LeetCode题解:Reorder List
- Leetcode: Reorder List
- LeetCode:Reorder List
- leetcode之Reorder List
- Leetcode: Reorder List
- [LeetCode]Reorder List
- [LeetCode] Reorder List
- leetcode Reorder List
- eclipse的tomcat的work目录位置
- 由Git的SSH公钥到非对称加密
- MERGE语句
- 时序图学习(二)
- 专注于书箱的网站
- 【LeetCode with Python】 Reorder List
- 点击按钮,实现用户签到
- rails4 部署到heroku 全
- SDL2垂直同步
- Linux 下的cat命令用法
- 对于内存越界访问的笔记
- Jmeter连接MySql
- 资源爬虫源码
- 【LeetCode with Python】 Roman to Integer