wyefei88
BAN USER
Comments (4)
Reputation 20
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
def reverseK(head, k):
if head == None:
return head
data = reverse(head, k)
newHead = data[0]
newTail = data[1]
nextHead = data[2]
while nextHead:
data = reverse(nextHead, k)
newTail.setNext(data[0])
newTail = data[1]
nextHead = data[2]
return newHead
# helper function
def reverse(head, k):
originalHead = head
prevHead = None
for i in range(k):
if head == None:
break
tmp = head.getNext()
head.setNext(prevHead)
prevHead = head
head = tmp
return (prevHead, originalHead, head)
using it by calling
head = reverseK(a, 3)
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
obviously, this site doesn't have a good python parser
- wyefei88 May 05, 2012