Rotate List

Given the head of a linked list, rotate the list to the right by k places.

Constraints

  • The number of nodes in the list is in the range [0, 500].
  • -100 <= Node.val <= 100
  • 0 <= k <= 2 * 10^9
Saving… · 10 lines
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next

class Solution:
def rotateList(self, head: ListNode, k: int) -> ListNode:


Console

Click Run to execute sample tests.