Blog Archive

Saturday, September 13, 2014

[leetcode]Rotate List @ Python - 南郭子綦 - 博客园

[leetcode]Rotate List @ Python - 南郭子綦 - 博客园: " if k == 0:
return head
if head == None:
return head
dummy = ListNode(0)
dummy.next = head
p = dummy
count = 0
while p.next:
p = p.next
count += 1
p.next = dummy.next
step = count - ( k % count )
for i in range(0, step):
p = p.next
head = p.next
p.next = None
return head"



'via Blog this'

No comments:

Post a Comment