leetcode725
Posted asenyang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode725相关的知识,希望对你有一定的参考价值。
1 class Solution: 2 def splitListToParts(self, root: ‘ListNode‘, k: int) -> ‘List[ListNode]‘: 3 N = 0 4 cur = root 5 while cur != None: 6 N += 1 7 cur = cur.next 8 mod = N % k 9 size = N // k 10 ret = [] 11 cur = root 12 i = 0 13 while i < k: 14 if cur != None: 15 ret.append(cur) 16 else: 17 ret.append([]) 18 apdx = 1 if mod > 0 else 0 19 mod -= 1 20 curSize = size + apdx 21 for j in range(curSize-1): 22 cur = cur.next 23 if cur != None: 24 nexNode = cur.next 25 cur.next = None 26 cur = nexNode 27 i += 1 28 return ret
以上是关于leetcode725的主要内容,如果未能解决你的问题,请参考以下文章
Leetcode 725. Split Linked List in Parts
LeetCode 725 分隔链表[链表 双指针] HERODING的LeetCode之路
LeetCode 725. Split Linked List in Parts (分裂链表)
[leetcode]725. Split Linked List in Parts链表分块
LeetCode 725. 分隔链表 / 326. 3的幂 / 剑指 Offer 62. 圆圈中最后剩下的数字(约瑟夫环问题)