문제 : 61. Rotate List
문제는 간단하다.
linked list가 주어지고 k만큼 오른쪽으로 회전한 결과값을 반환하면 된다.
from collections import deque
class Solution(object):
def rotateRight(self, head, k):
if head == None:
return None
answer = deque()
curr = head
while curr:
if curr.next == None:
answer.append(curr.val)
break
answer.append(curr.val)
curr = curr.next
answer.rotate(k)
listNode = ListNode(answer[0])
curr_node = listNode
for i in range(1,len(answer)):
new_node = ListNode(answer[i])
curr_node.next = new_node
curr_node = curr_node.next
return listNode
listNode = ListNode(answer[0])
for i in range(1,len(answer)):
new_node = ListNode(answer[i])
listNode.next = new_node
listNode = listNode.next
return listNode