Right Rotation
Given a list of numbers nums and a non-negative integer k, rotate the list to the right by k positions. The elements from the end move back to the beginning, like the list is wrapping around in a circle. If k is larger than the list length, full extra rotations do not change the result. Return the new rotated list.
Примеры
Ввод
[1, 2, 3, 4, 5], 2Вывод
[4, 5, 1, 2, 3]Ввод
[1, 2, 3], 4Вывод
[3, 1, 2]Ввод
[], 3Вывод
[]Нужно реализовать
def rotate_right(nums: list[int], k: int) -> list[int]:
Теги
array
Melde dich an, um den Einreichungsverlauf zu sehen
AnmeldenMelde dich an, um den KI-Mentor zu nutzen
AnmeldenVisible tests
1
Input
[1,2,3,4,5], 2Expected
[4,5,1,2,3]2
Input
[1,2,3], 4Expected
[3,1,2]3
Input
[], 3Expected
[]4
Input
[5,4,3,2,1], -2Expected
[3,2,1,5,4]5
Input
[2,3,4,5,6], 2Expected
[5,6,2,3,4]6
Input
[0,0,0,0,0], 2Expected
[0,0,0,0,0]Focus radio
Paused · SomaFM · Fluid